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 に答える