Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Issue after copying data
Message
De
30/11/2010 15:19:29
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Scripting
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01491153
Message ID:
01491178
Vues:
29
>>Yeah, but that complains when I have FK constraints set.
>
>Take a look at this blog post
>
>Delete all data in all tables in a database when you have foreign keys
>
>From comment by Denis Gobo to this blog post:
>
>
>-- disable referential integrity
>EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL' 
>GO 
>
>EXEC sp_MSForEachTable 'TRUNCATE TABLE ?' 
>GO 
>
>-- enable referential integrity again 
>EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL' 
>GO 
>
Hmmm, I run the following:
EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'
GO
EXEC sp_MSForEachTable 'TRUNCATE TABLE ?' 
GO
EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL' 
and I get
Cannot truncate table 'dbo.aspnet_Roles' because it is being referenced by a FOREIGN KEY constraint.
Very fitting: http://xkcd.com/386/
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform