0
CREATE TABLE P_OWNER(
     OWNERID               CHAR(5) NOT NULL,
     LNAME                 VARCHAR2(50) NOT NULL, 
     FNAME                 VARCHAR2(30) NULL, 
     SSN                   CHAR(9) NULL, 
     EMAIL                 VARCHAR2(50) NULL,
     CONSTRAINT            P_OWNER_PK      PRIMARY KEY(OWNERID),
     CONSTRAINT            P_OWNER_AK1     ALTERNATE KEY(SSN),
     CONSTRAINT            P_OWNER_AK2     ALTERNATE KEY(EMAIL)
     );

CREATE TABLE P_PROPERTY(
     PROPERTYID            CHAR(5) NOT NULL, 
     STREET1               VARCHAR2(50) NOT NULL, 
     STREET2               VARCHAR2(50) NULL, 
     CITY                  VARCHAR2(50) DEFAULT 'FITCHBURG',
     STATE                 CHAR(2) DEFAULT 'MA',
     ZIP                   CHAR(10) NULL,
     SQFOOTAGE             NUMBER(5,0) NULL, 
     HAS_AC                CHAR(1) NULL,
     ISHOUSE               CHAR(1) NOT NULL,
     CONSTRAINT            P_PROPERTY_PK              PRIMARY KEY(PROPERTYID),
     CONSTRAINT            P_PROPERTY_ADDRESS_AK1     ALTERNATE KEY(CITY, STATE, STREET1, STREET2, ZIP)
     );





Error at Command Line:8 Column:57
Error report:
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 -  "missing right parenthesis"
*Cause:    
*Action:
4

3 回答 3

2

你想要一个唯一键而不是备用键

   CREATE TABLE P_OWNER(
 OWNERID               CHAR(5) NOT NULL,
 LNAME                 VARCHAR2(50) NOT NULL, 
 FNAME                 VARCHAR2(30) NULL, 
 SSN                   CHAR(9) NULL, 
 EMAIL                 VARCHAR2(50) NULL,
 CONSTRAINT            P_OWNER_PK      PRIMARY KEY(OWNERID),
 CONSTRAINT            P_OWNER_AK1     UNIQUE(SSN),
 CONSTRAINT            P_OWNER_AK2     UNIQUE(EMAIL)
 );


 CREATE TABLE P_PROPERTY(
 PROPERTYID            CHAR(5) NOT NULL, 
 STREET1               VARCHAR2(50) NOT NULL, 
 STREET2               VARCHAR2(50) NULL, 
 CITY                  VARCHAR2(50) DEFAULT 'FITCHBURG',
 STATE                 CHAR(2) DEFAULT 'MA',
 ZIP                   CHAR(10) NULL,
 SQFOOTAGE             NUMBER(5,0) NULL, 
 HAS_AC                CHAR(1) NULL,
 ISHOUSE               CHAR(1) NOT NULL,
 CONSTRAINT            P_PROPERTY_PK              PRIMARY KEY(PROPERTYID),
 CONSTRAINT            P_PROPERTY_ADDRESS_AK1     UNIQUE(CITY, STATE, STREET1, STREET2, ZIP)
 );
于 2013-04-16T04:48:25.453 回答
2

问题在于ALTERNATE KEY尝试 UNIQUE

CREATE TABLE P_OWNER(
     OWNERID               CHAR(5) NOT NULL,
     LNAME                 VARCHAR2(50) NOT NULL, 
     FNAME                 VARCHAR2(30) NULL, 
     SSN                   CHAR(9) NULL, 
     EMAIL                 VARCHAR2(50) NULL,
     CONSTRAINT            P_OWNER_PK      PRIMARY KEY(OWNERID),
     CONSTRAINT            P_OWNER_AK1     UNIQUE (SSN),
     CONSTRAINT            P_OWNER_AK2     UNIQUE (EMAIL)
     );

CREATE TABLE P_PROPERTY(
     PROPERTYID            CHAR(5) NOT NULL, 
     STREET1               VARCHAR2(50) NOT NULL, 
     STREET2               VARCHAR2(50) NULL, 
     CITY                  VARCHAR2(50) DEFAULT 'FITCHBURG',
     STATE                 CHAR(2) DEFAULT 'MA',
     ZIP                   CHAR(10) NULL,
     SQFOOTAGE             NUMBER(5,0) NULL, 
     HAS_AC                CHAR(1) NULL,
     ISHOUSE               CHAR(1) NOT NULL,
     CONSTRAINT            P_PROPERTY_PK              PRIMARY KEY(PROPERTYID),
     CONSTRAINT            P_PROPERTY_ADDRESS_AK1     UNIQUE(CITY, STATE, STREET1, STREET2, ZIP)
     );
于 2013-04-16T04:48:44.740 回答
0

Analternate key (or secondary key)是未选择为主键 (PK) 的任何候选键。您不能在 Oracle 中创建备用键,它只是概念性的。

于 2013-04-16T04:49:54.250 回答