日期:2014-05-17  浏览次数:20861 次

菜鸟问个关于Oracle建表的问题
CREATE   TABLE   Emp(
eid   INTEGER,
ename   CHAR(80),
age   INTEGER,
salary   REAL,
PRIMARY   KEY   (eid),
FOREIGN   KEY   (eid)   REFERENCES   Works  
ON   DELETE   CASCADE
ON   UPDATE   CASCADE
                                )

CREATE   TABLE   Works(
eid   INTEGER,
did   INTEGER,
pct_time   INTEGER,
PRIMARY   KEY   (eid,did),
FOREIGN   KEY   (did)   REFERENCES   Dept
ON   DELETE   CASCADE
ON   UPDATE   CASCADE,
                                 
FOREIGN   KEY   (eid)   REFERENCES   Emp
ON   DELETE   CASCADE
ON   UPDATE   CASCADE
                        )

CREATE   TABLE   Dept(
did   INTEGER,
dname   CHAR(80),
budget   REAL,
managerid   INTEGER,
PRIMARY   KEY   (did),
FOREIGN   KEY   (did)   REFERENCES   Works
ON   DELETE   CASCADE
ON   UPDATE   CASCADE
                                                                     
)
我就是很简单的建了3张表,可是数据库老是报错说

ORA-00907:   missing   right   parenthesis

到底是什么毛病啊,希望大家能帮帮忙。




------解决方案--------------------
1,emp创建时其外键所指向的表works并不存在;
2,报错内容是缺少右括号,原因是ondeletecascade和on update cascade不能重复使用?
CREATE TABLE Emp(
eid INTEGER,
ename CHAR(80),
age INTEGER,
salary REAL,
PRIMARY KEY (eid)
--FOREIGN KEY (eid) REFERENCES Works
)

CREATE TABLE Works(
eid INTEGER,
did INTEGER,
pct_time INTEGER,
PRIMARY KEY (eid,did),

FOREIGN KEY (eid) REFERENCES Emp
ON DELETE CASCADE
)

CREATE TABLE Dept(
did INTEGER,
dname CHAR(80),
budget REAL,
managerid INTEGER,
PRIMARY KEY (did),
FOREIGN KEY (did) REFERENCES Works
ON DELETE CASCADE
)