Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating Table that has multiple Foreign Keys in Oracle

Tags:

oracle

I'm trying to create a table of ENCOUNTER entity. I have successfully created all the foreign key tables associated with this table, but when I try to run it on Oracle Database Express Edition 11g, it's keep giving the following error message, and I cannot find any error. ORA-00907: missing right parenthesis Below is the command syntax.

CREATE TABLE ENCOUNTER (
ENCT_ID VARCHAR2(25) PRIMARY KEY,
ENCT_DATE DATE NOT NULL,
PT_MRN NUMBER NOT NULL,
ENCT_BP VARCHAR2(10) NOT NULL,
ENCT_WT NUMBER(3,2) NOT NULL,
ENCT_TEMP NUMBER(3) NOT NULL,
ACCT_ID VARCHAR2(25) NOT NULL,
PHX_ID VARCHAR2(25) NOT NULL,
CONSTRAINT FK_PATIENT FOREIGN KEY (PT_MRN) REFERENCES PATIENT(PT_MRN)
CONSTRAINT FK_ACCOUNT FOREIGN KEY (ACCT_ID) REFERENCES ACCOUNT(ACCT_ID)
CONSTRAINT FK_PTHISTORY FOREIGN KEY (PHX_ID) REFERENCES PTHISTORY(PHX_ID));
like image 311
SGIL Avatar asked Jun 16 '15 18:06

SGIL


People also ask

Can we have two foreign keys in a table in Oracle?

A table can have multiple foreign keys based on the requirement.

Can a table contains multiple foreign keys?

A table may have multiple foreign keys, and each foreign key can have a different parent table. Each foreign key is enforced independently by the database system. Therefore, cascading relationships between tables can be established using foreign keys.

How many foreign keys can a table have in Oracle?

A table can reference a maximum of 253 other tables and columns as foreign keys (Outgoing Foreign Key References).


1 Answers

I believe you are missing commas after each constraint.

CREATE TABLE ENCOUNTER (
ENCT_ID VARCHAR2(25) PRIMARY KEY,
ENCT_DATE DATE NOT NULL,
PT_MRN NUMBER NOT NULL,
ENCT_BP VARCHAR2(10) NOT NULL,
ENCT_WT NUMBER(3,2) NOT NULL,
ENCT_TEMP NUMBER(3) NOT NULL,
ACCT_ID VARCHAR2(25) NOT NULL,
PHX_ID VARCHAR2(25) NOT NULL,
CONSTRAINT FK_PATIENT FOREIGN KEY (PT_MRN) REFERENCES PATIENT(PT_MRN),
CONSTRAINT FK_ACCOUNT FOREIGN KEY (ACCT_ID) REFERENCES ACCOUNT(ACCT_ID),
CONSTRAINT FK_PTHISTORY FOREIGN KEY (PHX_ID) REFERENCES PTHISTORY (PHX_ID));
like image 127
jongusmoe Avatar answered Sep 28 '22 09:09

jongusmoe