Create Foreign Keys

  • Thread starter Thread starter peterfarge
  • Start date Start date
P

peterfarge

Hello Forum,

how can I create a Foreign Key within a SQL Table Create Statement?
- Create Table Person (ID Int NOT NULL PRIMARY KEY, Name VARCHAR(255))
- Create Table Employees (ID Int NOT NULL PRIMARY KEY, PersonID INT
NOT NULL FOREIGN KEY REFERENCES Person(ID))

The message is "Syntax Error in Constraint Clause".


Thanks

Peter
 
peterfarge said:
Hello Forum,

how can I create a Foreign Key within a SQL Table Create Statement?
- Create Table Person (ID Int NOT NULL PRIMARY KEY, Name VARCHAR(255))
- Create Table Employees (ID Int NOT NULL PRIMARY KEY, PersonID INT
NOT NULL FOREIGN KEY REFERENCES Person(ID))

The message is "Syntax Error in Constraint Clause".


CREATE TABLE Employees
(
ID Int NOT NULL PRIMARY KEY,
PersonID INT NOT NULL
CONSTRAINT FKPersonID REFERENCES Person(ID)
)
 
Back
Top