Wednesday, November 12, 2008

Remove FK from a table

IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[FK_Clients_Users]') AND type = 'F')
ALTER TABLE [dbo].[Clients] DROP CONSTRAINT [FK_Clients_Users]
GO

-- after that we're now able to for example drop the FK column

ALTER TABLE [dbo].[Clients] DROP COLUMN [UserID]
GO

No comments: