CREATE TABLE PRESCRIPTION
(
prescription_no NUMBER (7),
CONSTRAINT prescription_no_pk PRIMARY KEY,
pr_patient_no VARCHAR2(6),
CONSTRAINT pr_patient_no_fk FOREIGN KEY(patient) REFERENCES (patient_no),
pr_drug_no NUMBER(5),
CONSTRAINT pr_drug_no_fk FOREIGN KEY (drug) REFERENCES (drug_no),
drug_start_date DATE,
units_per_day NUMBER(3,2),
drug_end_date DATE
);
答案 0 :(得分:0)
尝试以下查询我更改了您的查询:
CREATE TABLE PRESCRIPTION
(
prescription_no NUMBER (7) CONSTRAINT prescription_no_pk PRIMARY KEY,
pr_patient_no VARCHAR2(6) CONSTRAINT pr_patient_no_fk FOREIGN KEY(patient)
REFERENCES (patient_no),
pr_drug_no NUMBER(5) CONSTRAINT pr_drug_no_fk FOREIGN KEY (drug)
REFERENCES (drug_no),
drug_start_date DATE,
units_per_day NUMBER(3,2),
drug_end_date DATE
);
答案 1 :(得分:0)
FOREIGN KEY约束具有以下语法:
FOREIGN KEY (<this table's column name>) REFERENCES <another table>(<another table's column name>)
。
在您的示例中,假设patient
具有以下架构:
CREATE TABLE patient (
patient_no VARCHAR2(6),
primary key (patient_no)
)
您可以按如下方式引用它:
CREATE TABLE PRESCRIPTION (
prescription_no NUMBER (7),
pr_patient_no VARCHAR2(6) ,
CONSTRAINT prescription_no_pk PRIMARY KEY (prescription_no),
CONSTRAINT pr_patient_no_fk FOREIGN KEY (pr_patient_no) REFERENCES patient(patient_no)
)
等等。