Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2009
    Posts
    6

    Red face Unanswered: proble in foreign key

    can any body tell me what is erroe in following ranscript


    create table course(
    crs_id number(4)
    constraint crs_id primary key,
    crs_name varchar2(20));







    create table teacher(
    tech_id number(4)
    constraint tech_id primary key,
    tech_name varchar2(20),
    tech_address varchar2(30),
    tech_contact number(15),
    campus_id number(4) NOT NULL,
    dept_id number(4) NOT NULL);








    create table result(
    res_id number(10)
    constraint res_id primary key,
    std_det_id number(4) NOT NULL,
    total_marks number(3),
    marks_obtained number(3));








    create table student_detail(
    std_det_id number(4)
    constraint std_det_id primary key,
    std_id number(4) NOT NULL,
    crs_id number(4) NOT NULL,
    semester varchar2(10));





    create table student(
    std_id number(4)
    constraint std_id primary key,
    std_name varchar2(20) not null,
    std_address varchar2(30),
    std_contact number(15),
    camp_id number(4) NOT NULL,
    dept_id number(4) NOT NULL);




    create table taecher_detail(
    tech_det_id number(4)
    constraint tech_det_id primary key,
    tech_id number(4) NOT NULL,
    crs_id number(4) NOT NULL,
    semester varchar2(10));







    create table campus(
    camp_id number(4)
    constraint camp_id primary key,
    camp_name varchar2(20));






    create table department(
    dept_id number(4)
    constraint dept_id primary key,
    dept_name varchar2(10));





    alter table teacher
    add constraint tech_camp-fk
    foreign key camp_id
    reference campus(camp_id),
    add constraint tech_dept-fk
    foreign key dept_id
    reference department(dept_id);



    alter table result
    add constraint result_std_det-fk
    foreign key std_det_id
    reference student_detail(std_det_id);


    alter table student_detail
    add constraint std_det_std-fk
    foreign key std_id
    reference student(std_id),
    add constraint std_det_crs_fk
    foreign key crs_id
    reference course(crs_id);



    alter table student
    add constraint std_camp-fk
    foreign key camp_id
    reference campus(camp_id),
    add constraint std_dept-fk
    foreign key dept_id
    reference department(dept_id);


    alter table teacher_detail
    add constraint tech_det_tech-fk
    foreign key tech_id
    reference teacher(tech_id),
    add constraint tech_det_crs_fk
    foreign key crs_id
    reference course(crs_id);

  2. #2
    Join Date
    Aug 2009
    Posts
    262
    create table course(
    crs_id number(4)
    constraint crs_id primary key,
    crs_name varchar2(20));







    create table teacher(
    tech_id number(4)
    constraint tech_id primary key,
    tech_name varchar2(20),
    tech_address varchar2(30),
    tech_contact number(15),
    campus_id number(4) NOT NULL,
    dept_id number(4) NOT NULL);








    create table result(
    res_id number(10)
    constraint res_id primary key,
    std_det_id number(4) NOT NULL,
    total_marks number(3),
    marks_obtained number(3));








    create table student_detail(
    std_det_id number(4)
    constraint std_det_id primary key,
    std_id number(4) NOT NULL,
    crs_id number(4) NOT NULL,
    semester varchar2(10));





    create table student(
    std_id number(4)
    constraint std_id primary key,
    std_name varchar2(20) not null,
    std_address varchar2(30),
    std_contact number(15),
    camp_id number(4) NOT NULL,
    dept_id number(4) NOT NULL);




    create table taecher_detail(
    tech_det_id number(4)
    constraint tech_det_id primary key,
    tech_id number(4) NOT NULL,
    crs_id number(4) NOT NULL,
    semester varchar2(10));

    the table name should be TEACHER_DETAIL not tAEcher_detail;

    create table teacher_detail(
    tech_det_id number(4)
    constraint tech_det_id primary key,
    tech_id number(4) NOT NULL,
    crs_id number(4) NOT NULL,
    semester varchar2(10));






    create table campus(
    camp_id number(4)
    constraint camp_id primary key,
    camp_name varchar2(20));






    create table department(
    dept_id number(4)
    constraint dept_id primary key,
    dept_name varchar2(10));





    alter table teacher
    add constraint tech_camp_fk
    foreign key( campus_id)
    references campus(camp_id);


    alter table teacher
    add constraint tech_dept_fk
    foreign key (dept_id)
    references department(dept_id);


    you cannot name a constraint with '-'



    alter table result
    add constraint result_std_det_fk
    foreign key (std_det_id)
    references student_detail(std_det_id);


    alter table student_detail
    add constraint std_det_std_fk
    foreign key (std_id)
    references student(std_id);

    alter table student_detail
    add constraint std_det_crs_fk
    foreign key (crs_id)
    references course(crs_id);


    alter table student
    add constraint std_camp_fk
    foreign key (camp_id)
    references campus(camp_id);

    alter table student
    add constraint
    std_dept_fk
    foreign key (dept_id)
    references department(dept_id);


    alter table teacher_detail
    add constraint tech_det_tech_fk
    foreign key (tech_id)
    references teacher(tech_id);

    alter table teacher_Detail
    add constraint tech_det_crs_fk
    foreign key (crs_id)
    references course(crs_id);


    APPARENTLY you do not seem to care about your typing mistake and come here with a long face asking what is wrong . The only thing wrong here is your lack of attention and pardon me if i say , you are making a fool of yourself .

    regards
    Last edited by mishaalsy; 11-10-09 at 05:54.

  3. #3
    Join Date
    Oct 2009
    Posts
    6
    thank u for kind solution u r right i m in great confusion

  4. #4
    Join Date
    Oct 2009
    Posts
    6
    thank u for kind solution u r right i m in great confusion

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •