ivivjcb
ivivjcb

Reputation: 218

What's wrong with the syntax of this SQL command

No matter how long I look at it I can't find the error. I put it in a syntax checker online and it said the error was around the ending line.

CREATE TABLE employee (
emp_ID      INT             (30) NOT NULL, 
position        VARCHAR     (30) NOT NULL, 
emp_FName   VARCHAR     (30) NOT NULL,
emp_LName   VARCHAR     (30) NOT NULL, 
ohip        VARCHAR     (15) NOT NULL, 
home_Phone  INT         (15), 
start_Date  DATE, 
team_ID INT             (30) NOT NULL,  

Constraint     employee_emp_ID_PK       Primary Key (emp_ID),
Constraint     employee_team_ID_FK      Foreign Key (team_ID) 

)

Upvotes: 0

Views: 55

Answers (2)

Rima
Rima

Reputation: 1455

For foreign key please specify reference table and its primary key.

  CREATE TABLE employee (
    emp_ID      INT              NOT NULL  Primary Key, 
    position    VARCHAR     (30) NOT NULL, 
    emp_FName   VARCHAR     (30) NOT NULL,
    emp_LName   VARCHAR     (30) NOT NULL, 
    ohip        VARCHAR     (15) NOT NULL, 
    home_Phone  INT          , 
    start_Date  DATE, 
    team_ID INT              NOT NULL FOREIGN KEY REFERENCES reftable(ID),  

     )

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1269753

A foreign key needs to references something. So, presumably:

Constraint employee_team_ID_FK Foreign Key (team_ID) references teams(team_id)

or something like that.

In addition, I'm not sure what you mean by int(30). This is merely the display width for the value, and because integers can have only 10 digits (well, 11 if you include a negative sign), 30 doesn't make sense.

Upvotes: 2

Related Questions