Foreign keys in SQL CE

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

How can I create foreign keys in SQL CE database?

And why this SQL generates error?

ALTER TABLE company_contacts ADD
CONSTRAINT FK_company_contacts_companies FOREIGN KEY
(
company_id
) REFERENCES companies (
id
) ON DELETE CASCADE
 
Hi Dave!

I typically create a constrain by putting the following statement after
the declaration of the column when I create a table:

CONSTRAINT <MyConstrainName> references <MyTableName>(<MyColumnName>)

The "MyConstrainName" must be unique in all the database.

About your statement, I think it has too many fancy commands. SQLCE is a
really compact version of MSSQL, so don't expect to have all the nice
features.

Hope it helps!!!

Tarh ik
Note: This post is "AS IS"
 
This code fragment works for me.

ALTER TABLE TreatmentLines ADD CONSTRAINT FK_TreatmentLines_Treatments
FOREIGN KEY (TreatmentRef) REFERENCES Treatments (Ref) ON DELETE CASCADE
 
Back
Top