Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
After test, I need insert real data in about 50 tables. How to code to trucate 50 tables?
spirit1
Cybernetic Yak Master
11752 Posts
Posted - 2005-11-11 : 19:17:29
exec sp_MSforeachtable N"truncate table ? where ? <> 'dtproperties'"use begin tran ... rollback for testing purposes.Go with the flow & have fun! Else fight the flow
Kristen
Test
22859 Posts
Posted - 2005-11-12 : 05:49:39
I use this to make a script that I check, remove some tables from , and then run
select 'TRUNCATE TABLE ' + db_name() + '.dbo.[' + name + ']', CHAR(13)+CHAR(10)+'GO'from sysobjects where type = 'u' and name not in ('dtproperties') -- System tables-- and name not in ('XXX', 'YYY') -- "Do not delete" tables-- and name not like '%y%' ESCAPE '\' -- Other "wildcard" names to NOT deleteorder by [NAME]