Create Foreign Keys

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
 
D

Dirk Goldgar

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)
)
 
Top