Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Drop constraint if exist syntax
Message
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Titre:
Drop constraint if exist syntax
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01547008
Message ID:
01547008
Vues:
64
Hi,

I have been looking on various sites for the code to drop a constraint if I know the name of the constraint. Each site has a different code. I am confused. I would like something that would work on SQL Server 2005 and SQL Server 2008. What would you recommend?

TIA.

UPDATE. This is the code that works on my SQL Server 2008. Does it look like the right one?:
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FK_table_name_fk_field]') 
     AND parent_object_id = OBJECT_ID(N'[dbo].[table_name]'))
	BEGIN
		ALTER TABLE [dbo].[table_name] 
		DROP CONSTRAINT [FK_table_name_fk_field]
	END
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform