Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check for existence of foreign key

Status
Not open for further replies.

loydall

Programmer
Apr 4, 2001
12
GB
Hi - I need to delete a foreign key programatically but, obviously, only if it exists.

I'm in MS SQL Server 2005.

I need to delete a Foreign called fkUserRoleID on a table called tblUsers.

Any ideas?

Thanks.
 
Code:
IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS WHERE Constraint_Name = 'fkUserRoleID')
   BEGIN
       ALTER TABLE dbo.??????????
	DROP CONSTRAINT fkUserRoleID
   END

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
Microsoft MVP VFP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top