Remove FK CONSTRAINT

IF EXISTS (SELECT * FROM sys.foreign_keys
WHERE object_id = OBJECT_ID(N'[dbo].[FK_Name]’)
AND parent_object_id = OBJECT_ID(N'[dbo].[ChildTableName]’))
ALTER TABLE [dbo].[ChildTableName]
DROP CONSTRAINT [FK_Name]
GO
————————————————————————–

ALTER TABLE [dbo].[ChildTableName] WITH CHECK ADD CONSTRAINT [FK_Name] FOREIGN KEY([FKIDName])
REFERENCES [dbo].[MasterTableName] ([MasterPKID])
GO
ALTER TABLE [dbo].[ChildTableName] CHECK CONSTRAINT [FK_Name]
GO

——————————————————————-

Advertisements

~ by UTS on April 21, 2009.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: