我创建了两个表:
CREATE TABLE CIS_FACULTY2(
F_ID NUMBER(5)
CONSTRAINT CIS_FACULTY2_F_ID_FK PRIMARY KEY,
F_LAST VARCHAR(30),
F_FIRST VARCHAR(30),
F_MI CHAR(1),
LOC_ID NUMBER(5),
F_PHONE CHAR(10),
F_RANK CHAR(10),
F_SUPER NUMBER(6),
F_PIN NUMBER(4)
);
和
CREATE TABLE CIS_STUDENT2(
S_ID NUMBER(5)
CONSTRAINT CIS_STUDENT2_S_ID_PK PRIMARY KEY,
S_LAST VARCHAR(50),
S_FIRST VARCHAR(30),
S_MI CHAR(30),
S_ADDRESS VARCHAR(25),
S_CITY VARCHAR(20),
S_STATE CHAR(2),
S_ZIP CHAR(10),
S_PHONE CHAR(10),
S_CLASS CHAR(2),
S_DOB DATE,
S_PIN NUMBER(4),
F_ID NUMBER(5)
CONSTRAINT CIS_STUDENT2_F_ID_FK
FOREIGN KEY F_ID REFERENCES (CIS_FACULTY2),
S_ENROLL_START_DATE DATE,
S_GRAD_DATE DATE);
我得到错误:在引入我的外键时,第二个表上不允许使用Oracle约束规范。任何帮助或建议将不胜感激。
答案 0 :(得分:0)
内联外键约束可以定义如下:
CREATE TABLE CIS_STUDENT2(
S_ID NUMBER(5)
CONSTRAINT CIS_STUDENT2_S_ID_PK PRIMARY KEY,
S_LAST VARCHAR(50),
S_FIRST VARCHAR(30),
S_MI CHAR(30),
S_ADDRESS VARCHAR(25),
S_CITY VARCHAR(20),
S_STATE CHAR(2),
S_ZIP CHAR(10),
S_PHONE CHAR(10),
S_CLASS CHAR(2),
S_DOB DATE,
S_PIN NUMBER(4),
F_ID NUMBER(5) CONSTRAINT CIS_STUDENT2_F_ID_FK REFERENCES CIS_FACULTY2(F_ID),
S_ENROLL_START_DATE DATE,
S_GRAD_DATE DATE);
或强>
外键外键约束可以定义如下:
CREATE TABLE CIS_STUDENT2(
S_ID NUMBER(5)
CONSTRAINT CIS_STUDENT2_S_ID_PK PRIMARY KEY,
S_LAST VARCHAR(50),
S_FIRST VARCHAR(30),
S_MI CHAR(30),
S_ADDRESS VARCHAR(25),
S_CITY VARCHAR(20),
S_STATE CHAR(2),
S_ZIP CHAR(10),
S_PHONE CHAR(10),
S_CLASS CHAR(2),
S_DOB DATE,
S_PIN NUMBER(4),
F_ID NUMBER(5),
S_ENROLL_START_DATE DATE,
S_GRAD_DATE DATE,
CONSTRAINT CIS_STUDENT2_F_ID_FK FOREIGN KEY(F_ID) REFERENCES CIS_FACULTY2(F_ID));