我在apex(Oracle)中设置FOREIGN KEY时遇到问题。首先我创建了地址表:
CREATE TABLE Address
(
AddressID integer NOT NULL PRIMARY KEY,
Country varchar2( 25 ) NOT NULL,
City_Village varchar2( 25 ) NOT NULL,
Street varchar2( 30 ) NOT NULL,
HomeNumber varchar2( 10 ) NOT NULL,
Apartment integer NULL
);
我尝试创建一个表Client:
CREATE TABLE Client
(
ClientID integer NOT NULL PRIMARY KEY,
LastName varchar2( 25 ) NOT NULL,
FirstName varchar2( 25 ) NOT NULL,
BirthDate Date NOT NULL,
Sex char( 1 ) NOT NULL,
PhoneNumber varchar2( 15 ) NULL,
Email varchar2( 25 ) NULL,
IDNP varchar2( 13 ) UNIQUE NOT NULL,
AddressId integer FOREIGN KEY REFERENCES Address( AddressID )
);
错误是ORA-00907:缺少右括号
我的代码出了什么问题?有人能帮助我吗?
答案 0 :(得分:0)
CREATE TABLE Client
(
ClientID integer NOT NULL PRIMARY KEY,
LastName varchar2( 25 ) NOT NULL,
FirstName varchar2( 25 ) NOT NULL,
BirthDate Date NOT NULL,
Sex char( 1 ) NOT NULL,
PhoneNumber varchar2( 15 ) NULL,
Email varchar2( 25 ) NULL,
IDNP varchar2( 13 ) UNIQUE NOT NULL,
AddressId integer ,
FOREIGN KEY AddressID REFERENCES Address( AddressID )
);
答案 1 :(得分:0)
试试这个
CREATE TABLE Client
(
ClientID integer NOT NULL PRIMARY KEY,
LastName varchar2( 25 ) NOT NULL,
FirstName varchar2( 25 ) NOT NULL,
BirthDate Date NOT NULL,
Sex char( 1 ) NOT NULL,
PhoneNumber varchar2( 15 ) NULL,
Email varchar2( 25 ) NULL,
IDNP varchar2( 13 ) UNIQUE NOT NULL,
AddressId integer REFERENCES Address( AddressID )
);