Foreign keys in SQL CE

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
 
G

Guest

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"
 
G

Guest

This code fragment works for me.

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

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