Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Removing constraints
Message
From
25/03/2011 01:11:26
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
Scripting
Title:
Removing constraints
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01504936
Message ID:
01504936
Views:
88
I have this nice script which removes constraints on the database:
DECLARE @ConstraintName nvarchar(128)
DECLARE @Command nvarchar(4000)

DECLARE TableTemporary CURSOR LOCAL FOR

Select 'ALTER TABLE '+tab.name+' DROP CONSTRAINT '+sysobjects.name
 From SysObjects
 INNER JOIN (Select [Name],[ID] From SysObjects Where XType = 'U') As 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]

OPEN TableTemporary
FETCH NEXT FROM TableTemporary INTO @ConstraintName
WHILE @@fetch_status = 0
BEGIN
   SET @Command = @ConstraintName
   EXEC sp_executesql @Command
   FETCH NEXT FROM TableTemporary into @ConstraintName
END
This has been tested well on two servers. Both are SQL Server 2005. When we moved that one into production, also a SQL Server 2005, we got this message:

"Incorrect syntax near the keyword 'Table'."

I have to say I am quite surprised as the three servers are identical. Anyone would know what could be in cause here?
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
Next
Reply
Map
View

Click here to load this message in the networking platform