Reputation: 9
So this is a table I am trying to create in relation to another table in my database. I know I have messed up the syntax somewhere, I'm just not sure where because oracle doesn't point out the exact line of error. Any help will be appreciated. And yes I'm new to this
CREATE TABLE USERS (
USER_ID NUMBER(5) PRIMARY KEY,
NAME VARCHAR2(255),
YEAR_OF_BIRTH YEAR,
SEX CHAR(2),
ADDRESS VARCHAR2(255),
PHONE_NUMBER VARCHAR2(20),
CA_ID NUMBER(5),
FOREIGN KEY CA_ID REFERENCES CANDIDATE(CANDIDATE_ID) ON DELETE NO ACTION
);
Upvotes: 0
Views: 83
Reputation: 167972
You need to:
YEAR_OF_BIRTH YEAR
to have a valid data type as YEAR
is not a valid data type.ON DELETE NO ACTION
is not syntactically correct. You cannot take no action if the item being referenced is deleted as then the constraint will be violated; instead you need to either set the value to NULL
or delete the record using CASCADE
or omit the ON DELETE
clause if you do not want the parent record to be able to be deleted if this child exists and references the parent.Like this:
CREATE TABLE USERS (
USER_ID NUMBER(5) PRIMARY KEY,
NAME VARCHAR2(255),
YEAR_OF_BIRTH NUMBER(4),
SEX CHAR(2),
ADDRESS VARCHAR2(255),
PHONE_NUMBER VARCHAR2(20),
CA_ID NUMBER(5),
FOREIGN KEY ( CA_ID ) REFERENCES CANDIDATE(CANDIDATE_ID ) ON DELETE SET NULL
);
Upvotes: 2