遗漏了左括号,我找不到错误。有人可以帮助我吗?

时间:2017-03-20 06:01:45

标签: sql oracle-sqldeveloper

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

2 个答案:

答案 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)
    )

等等。