Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Removing constraints
Message
De
25/03/2011 01:11:26
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Scripting
Titre:
Removing constraints
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Web
Divers
Thread ID:
01504936
Message ID:
01504936
Vues:
89
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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform