this blog contains information for .net and sql stuffs. You can find various tips and tricks to overcome problem you may be facing in ...

Monday, June 8, 2009

How to add Foreignkey Constraints to table?

Hello,

Some time we want to add foreign key constraints to table with out being open up table structure.


This is some useful syntax to add foreign key constraints while we are going to add any new column to table.

ALTER TABLE tblEmployee
ADD CityId INT
CONSTRAINT Fk_tblEmployee_tlkpCity
FOREIGN KEY (CityId)
REFERENCES tlkpCity(lkpTypeId)

Here we have tblEmployee , we want to add new cityId column and this will be foreign key for table tlkpCity.

No comments: