2014-09-21 124 views
-1

我在設置apex(Oracle)中的FOREIGN KEY時遇到問題。首先我創建地址表:SQL(Oracle)外鍵問題

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

我試圖創建一個客戶表:

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

試試這個

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

ORA-00907: missing right parenthesis

+0

該解決方案並不能說明問題。 – 2017-09-05 15:49:18

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