Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Delete all rows from all tables in a SQL Server Database

Delete all rows from all tables SQL server

Have you ever come across the problem to delete all rows from all tables available in a database? One of my colleagues asked me this question that how can we delete all records from multiple tables of a database. So, in this SQL tutorial, we are going to discuss, how we can delete all rows from all tables of a Sql Server Database.

Follow below steps with t-SQL delete all records from all tables from SQL server:

  • Disable all constraints first:-
EXEC sys.sp_msforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'
  • Execute a Delete or truncate operation on each table of the database:-
EXEC sys.sp_msforeachtable 'DELETE FROM ?'
  • Enable all constraints on the database:-
EXEC sys.sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'

sql query to delete all rows from all tables
Did you find this post useful? I hope you liked this article. Please share with me your valuable suggestions and feedback.

The post Delete all rows from all tables in a SQL Server Database appeared first on Dot Net Tutorial, C# Tutorial, Google Maps API JavaScript, Dot Net Tricks.



This post first appeared on Asp Dot Net Tricks And Tips, Dot Net Coding Tips, Google Maps API Developer, please read the originial post: here

Share the post

Delete all rows from all tables in a SQL Server Database

×

Subscribe to Asp Dot Net Tricks And Tips, Dot Net Coding Tips, Google Maps Api Developer

Get updates delivered right to your inbox!

Thank you for your subscription

×