Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Removing constraints
Message
 
 
À
25/03/2011 01:11:26
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Scripting
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Web
Divers
Thread ID:
01504936
Message ID:
01504964
Vues:
28
Take a look at the beginning of this blog post
http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/MSSQLServer/delete-all-data-in-database-when-you-hav

As you can see, all identifiers are put in [ ] and also Nikola uses just one command to delete all constraints at once (as Boris suggested also).

>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?
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform