Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Removing constraints
Message
From
25/03/2011 10:41:31
 
General information
Forum:
Microsoft SQL Server
Category:
Scripting
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01504936
Message ID:
01504985
Views:
30
>I would use this:
>
>DECLARE @ConstraintName nvarchar(128)
>DECLARE @Command nvarchar(max)
>SET @Command = ''
>Select @Command = @Command + 
>       'ALTER TABLE '+tab.name+' DROP CONSTRAINT '+sysobjects.name+CHAR(13)+CHAR(10)
>FROM SysObjects
>INNER JOIN (Select [Name],[ID] From SysObjects Where XType = 'U')  Tab
>       ON Tab.[ID] = Sysobjects.[Parent_Obj] 
>Inner Join sysconstraints On sysconstraints.Constid = Sysobjects.[ID] 
>Inner Join SysColumns Col On Col.[ColID] = sysconstraints.[ColID] And Col.[ID] = Tab.[ID]
>
>EXEC sp_executesql @Command
>
>
>but that is a matter of preferences :-)
>
>In your case you could add a print @Command before executing each line to see where you get the error.

Thanks, this is much simpler.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Previous
Reply
Map
View

Click here to load this message in the networking platform