gpt4 book ai didi

sql - "Missing Keyword"在 Oracle SQL Developer 中创建表时

转载 作者:搜寻专家 更新时间:2023-10-30 23:00:39 25 4
gpt4 key购买 nike

我不断得到

"SQL Error: ORA - 00905: missing keyword" in the "CREATE TABLE"

我的部分代码如下所示:

    CREATE TABLE Orders (
Received CHAR(9),
Shipped CHAR(9),
FOREIGN KEY (Ono), REFERENCES Odetails (Ono),
FOREIGN KEY (Cno), REFERENCES customers (Cno),
FOREIGN KEY (Eno), REFERENCES employee (Eno),
PRIMARY KEY (Ono, Cno, Eno)
);

CREATE TABLE ZIPCODES (
ZIP CHAR(5) NOT NULL,
City CHAR(20),
FOREIGN KEY (ZIP), REFERENCES customers (ZIP),
PRIMARY KEY (ZIP)
);

但是,我在同一个工作表中编写了这段代码,并且没有出现任何错误:

    CREATE TABLE Odetails (
Ono CHAR(4) NOT NULL,
Pno CHAR(5) NOT NULL,
Qty CHAR(1),
FOREIGN KEY (Pno), REFERENCES parts (Pno),
PRIMARY KEY (Ono)
);

任何人都可以帮助我确定导致错误的原因吗?

最佳答案

1) 不要使用逗号

2) 定义列

CREATE TABLE Orders (
Received CHAR(9),
Shipped CHAR(9),
Ono INT NOT NULL , -- your missing columns (add datatype you need)
Cno INT NOT NULL,
Eno INT NOT NULL,
FOREIGN KEY (Ono) REFERENCES Odetails (Ono), -- here no comma inside
FOREIGN KEY (Cno) REFERENCES customers (Cno),
FOREIGN KEY (Eno) REFERENCES employee (Eno),
PRIMARY KEY (Ono, Cno, Eno)
);

CREATE TABLE ZIPCODES (
ZIP CHAR(5) NOT NULL,
City CHAR(20),
FOREIGN KEY (ZIP) REFERENCES customers (ZIP),
PRIMARY KEY (ZIP)
);

考虑使用 VARCHAR2 数据类型代替 CHAR

您还可以使用内联语法,例如:

CREATE TABLE Orders (
...
Ono INT NOT NULL REFERENCES Odetails (Ono)
...
);

或添加显式约束名称:

CREATE TABLE Orders (
...
Ono INT NOT NULL,
...
CONSTRAINT FK_Orders_Odetails_Ono FOREIGN KEY (Ono) REFERENCES Odetails (Ono),
...
);

关于sql - "Missing Keyword"在 Oracle SQL Developer 中创建表时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33463940/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com