Uncategorized

Truncate all tables in database

Generated SQL commands to truncate all tables in the context database. Copy the SQL column and execute it. Remember, that TRUNCATE isn’t allowed for table referenced via a foreign key.

SELECT  
	[s].[name] [SchemaName], [t].[name] [TableName], 
	'TRUNCATE TABLE [' + [s].[name] + '].[' + [t].[name] + '];' [Sql]
FROM [sys].[tables] [t]
	INNER JOIN [sys].[schemas] [s] ON [s].[schema_id] = [t].[schema_id]
ORDER BY [Sql]
GO