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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top