Answer the question
In order to leave comments, you need to log in
How to bulk clear all tables at once in MsSql?
Hello!
How to bulk clear all tables at once in MsSql?
That to each table not to write truncate table.
Answer the question
In order to leave comments, you need to log in
Something like this:
declare @s nvarchar(max) = ''
select @s = @s +
'truncate table '+TABLE_NAME+';'
from INFORMATION_SCHEMA.TABLES
exec (@s)
Stupid, but "armor-piercing" option:
DECLARE @execute_cmd varchar(max)= '';
-- выбрать один из трех вариантов по вкусу
--SELECT @execute_cmd = @execute_cmd+'begin try truncate table ['+name+'] end try begin catch end catch ' FROM sys.tables WHERE type_desc = 'USER_TABLE';
--SELECT @execute_cmd = @execute_cmd+'begin try truncate table ['+TABLE_NAME+'] end try begin catch end catch ' FROM information_schema.tables WHERE TABLE_TYPE = 'BASE TABLE';
--SELECT @execute_cmd = @execute_cmd+'begin try truncate table ['+Name+'] end try begin catch end catch ' FROM dbo.sysobjects WHERE xtype = 'U';
EXECUTE @execute_cmd;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question