I just started sql and I have trouble creating a table with a foreign key. I created the parent table with no trouble but just can't seem to figure it out, any help please? thanks
the parent table:
Create table instructor(
InstructorName varchar(255) not null primary key,
instructoremaill varchar(255) not null,
biography varchar(255) not null,
specialty varchar(255) not null
);
And the code that is giving me troubles. I'm trying to create a table where, it will delete any sessions if an instructor is deleted from the database
Create table timetable(
number(10) not null,
dayandtime string not null,
numberofplaces number(10) not null,
classname varchar(255) not null,
venuename varchar(255) not null,
primary key (sessionid),
Constraint fk_instructorname
foreign key (instructorname)REFERENCES instructor(instructorname)
on delete cascade
);
Below changes are needed for table timetable
number(10) not null- missing column name
dayandtime string not null- No string datatype in oracle
primary key (sessionid) - should be like sessionid number primary key
Constraint fk_instructorname - There is missing of column instructorname definition (InstructorName varchar(255) not null)
--DDL for new table
Create table timetable(
col1 number(10) not null,
dayandtime varchar2(255) not null,
numberofplaces number(10) not null,
InstructorName varchar(255) not null,
classname varchar(255) not null,
venuename varchar(255) not null,
sessionid number primary key,
Constraint fk_instructorname
foreign key (instructorname) REFERENCES instructor(instructorname)
on delete cascade);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.