Wednesday 21 September 2016

Delete all Rows from All Available Table in SQL Server

Posted by : Manav Pandya



Delete all Rows from All Available Table in SQL Server

Delete all Rows from All Available Table in SQL Server

In this tutorial you will find that in specific situation you need to delete all rows having in Table in SQL Server , so that i have discuss here basic technique 

So try it and tell me if you have query regarding that



SELECT
'Delete from ' + Table_Catalog + '.' + Table_Schema + '.' + Table_Name + ';' 
FROM INFORMATION_SCHEMA.TABLES
WHERE Table_Type = 'BASE TABLE'
ORDER by TABLE_NAME


Another one is that , if your DB is large and you want to know how many tables are deleted you can write as follow :

SELECT
'Print(''Delete started for ' + Table_Catalog + '.' + Table_Schema + '.' + Table_Name + ''');' +
'Delete from ' + Table_Catalog + '.' + Table_Schema + '.' + Table_Name + ';' +
'Print(''Delete done for ' + Table_Catalog + '.' + Table_Schema + '.' + Table_Name + ''');'  +
'Print(''.............'');'
FROM INFORMATION_SCHEMA.TABLES
WHERE Table_Type = 'BASE TABLE'
ORDER by TABLE_NAME





sql server tips , ASP.NET MVC , MVC , Model View Controller , C# , ASP.NET , AJAX , We API , Silverlight , AngularJS , What is MVC in ASP.NET