簡體   English   中英

oracle sql,使用外鍵創建表

[英]oracle sql, creating table with foreign key

我剛剛啟動sql,但是在創建帶有外鍵的表時遇到了麻煩。 我毫不費力地創建了父表,但是似乎無法弄清楚,有什么幫助嗎? 謝謝

父表:

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
);

和給我帶來麻煩的代碼。 我正在嘗試創建一個表,如果從數據庫中刪除了講師,它將刪除所有會話

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
); 

時間表需要進行以下更改

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

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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM