Results 1 to 2 of 2
-
04-16-2012, 04:42 PM #1
- Join Date
- Apr 2008
- Location
- Boston, MA
- Posts
- 13,232
- Thanks
- 745
- Thanked 729 Times in 564 Posts
- Blog Entries
- 4
- Feedback Score
- 4 (100%)
How to Delete All Data From All Non-System Tables - MSSQL
Sometimes we need to clean data from all non-system tables before we can populate them with the fresh new set of data.
Here are couple of ways.
a) Delete data from all tables without resetting the identity columns
-- disable referential integrity
EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'
GO
EXEC sp_MSForEachTable 'DELETE FROM ?'
GO
-- enable referential integrity again
EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'
GO
b) Delete data from all tables resetting identity columns
-- 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'
GOFree Classified Ads & BUSINESS/PROFESSIONAL SOCIAL NETWORK
-
08-08-2012, 05:58 AM #2
Freshman
- Join Date
- Aug 2012
- Posts
- 12
- Thanks
- 0
- Thanked 0 Times in 0 Posts
- Feedback Score
- 0
i am agree with the above statement......
Similar Threads
-
Cannot perform '<=' operation on MySql.Data.Types.MySqlDateTime and System.String.
By brijeshtiwari1984 in forum Web Development - Programming & CodingReplies: 0Last Post: 02-01-2012, 03:51 AM -
How to Drop / Delete Tables / Stored Procedures / Views / Foreign Key Constraints / Functions
By mastermind in forum DatabasesReplies: 1Last Post: 10-13-2011, 09:00 AM -
Pulling Data From Multiple Tables
By slanluc in forum PHPReplies: 3Last Post: 08-25-2011, 03:28 AM -
How to test data loading in Data base testing ?
By deveshraigniit in forum DatabasesReplies: 4Last Post: 06-07-2011, 09:02 AM -
Windows | cPanel |.NET,ASP,AJAX,XML,MSSQL|@ 6.95!
By TEE06 in forum Other Hosting OffersReplies: 0Last Post: 08-18-2010, 03:33 PM



Reply With Quote

