I’m new to SQL language and i have started learning SQL language from youtube. As i follow the tutorial. it asked me to create a table in SQL(PostgreSQL) with the following code:
CREATE TABLE STAFF
(
STAFF_ID VARCHAR(20)
, STAFF_TYPE VARCHAR(30)
, SCHOOL_ID VARCHAR(20)
, FIRST_NAME VARCHAR(100) NOT NULL
, LAST_NAME VARCHAR(100) NOT NULL
, AGE INT
, DOB DATE
, GENDER VARCHAR(10) CHECK (GENDER IN ('M', 'F', 'Male', 'Female'))
, JOIN_DATE DATE
, ADDRESS_ID VARCHAR(20)
, CONSTRAINT PK_STAFF PRIMARY KEY(STAFF_ID)
, CONSTRAINT FK_STAFF_SCHL
FOREIGN KEY(SCHOOL_ID)
REFERENCES SCHOOL(SCHOOL_ID)
, CONSTRAINT FK_STAFF_ADDR
FOREIGN KEY(ADDRESS_ID)
REFERENCES ADDRESS(ADDRESS_ID)
);
as i run that command on my PostgrSQL Query tool. i got the below error Messages
ERROR: relation “school” does not exist
SQL state: 42P01
I’m able to create the table without FOREIGN KEY but when i cannot the table with FOREIGN KEY.
Can anyone explain the what is the issue with code?
Vineet Kumar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
4