我创建了我的桌子而且我被困在最后一个, 这是正确创建的表
CREATE TABLE Staff (
Staff_ID INT NOT NULL PRIMARY KEY,
First_Name VARCHAR(50),
Last_Name VARCHAR(50),
Username VARCHAR(10),
Password VARCHAR(10),
Address VARCHAR(30)
)
CREATE TABLE Category (
Category_ID INT NOT NULL PRIMARY KEY,
Name VARCHAR(30)
)
CREATE TABLE Author (
Author_ID INT NOT NULL PRIMARY KEY,
First_Name VARCHAR(50),
Last_Name VARCHAR(50),
Birth_Place VARCHAR(30),
Birth_Date DATE
)
CREATE TABLE Publisher (
Publisher_ID INT NOT NULL PRIMARY KEY,
Name VARCHAR(50)
)
这是我收到错误的那个:
CREATE TABLE Book (
Book_ID INT NOT NULL PRIMARY KEY,
Title VARCHAR(50),
Edition INT(30),
Year_Published INT(4),
FOREIGN KEY (Publisher_ID) REFERENCES Publisher(Publisher_ID),
FOREIGN KEY (Author_ID) REFERENCES Author(Author_ID),
FOREIGN KEY (Category_ID) REFERENCES Category(Category_ID)
)
错误说:
" ORA-00907:缺少右括号"
答案 0 :(得分:2)
INT不能与其关联,因此YEAR_PUBLISHED和EDITION的定义不正确。 我相信,一般来说,你最好坚持使用数字数据类型的NUMBER,例如NUMBER(4),NUMBER(30)。
在数据库中,INT数据类型只是NUMBER的子类型,因此您无法使用它获取任何内容:
type NUMBER is NUMBER_BASE;
subtype INTEGER is NUMBER(38,0);
subtype INT is INTEGER;
如果要查看各种“其他”数值数据类型的定义,请查看SYS.STANDARD包。
答案 1 :(得分:2)
INT
数据类型没有精确度。Publisher_ID
,Author_ID
和Category_ID
列。PRIMARY KEY
列同时为NOT NULL
和UNIQUE
,因此您无需包含第二个NOT NULL
约束。像这样:
CREATE TABLE Book (
Book_ID INT CONSTRAINT Book__Book_id__PK PRIMARY KEY,
Title VARCHAR(50),
Edition INT,
Year_Published INT,
Publisher_ID INT CONSTRAINT Book__Publisher_ID__FK REFERENCES Publisher(Publisher_ID),
Author_ID INT CONSTRAINT Book__Author_id__FK REFERENCES Author(Author_ID),
Category_ID INT CONSTRAINT Book__category_ID__FK REFERENCES Category(Category_ID)
);