forum.venkateswarlu.net
      Register      Login
sqlserver

1 replies to this topic

Saravanan Ramamoorhty #1
Member
58 Points
Posted on 14 Feb 2012 01:44 PM IST how to truncate all tables in a database in sqlserver using store procedure 
SQL Server     652 views     Reply to this topic
Subramaniam R #2
Member
152 Points
Replied on 30 Jul 2013 02:47 PM IST

CREATE

PROCEDURE [dbo].[usp_Truncate_AllTables]


AS


BEGIN


SET NOCOUNT ON;


DECLARE @List NVARCHAR(MAX)


SELECT @List=COALESCE(@List+',','')+Name FROM sys.Tables WHERE name not IN('sysdiagrams')


SELECT @List=REPLACE(REPLACE(@List,',',',TRUNCATE TABLE '),',',';')


SELECT @List='TRUNCATE TABLE '+@List


SELECT @List


EXEC (@List)


SET NOCOUNT OFF;


END

 
Reply to this topic