Skip to content

Instantly share code, notes, and snippets.

@simplement-e
Created April 14, 2013 12:59
Show Gist options
  • Select an option

  • Save simplement-e/5382634 to your computer and use it in GitHub Desktop.

Select an option

Save simplement-e/5382634 to your computer and use it in GitHub Desktop.
Vide toutes les tables non-système d'une base de données à coup de TRUNCATE TABLE / empty an entire database by running Truncate table on each user-table.
declare @stat nvarchar(500)
declare tbl_cursor cursor for
select 'truncate table [' + schemas.name + '].[' + tables.name + ']'
from sys.schemas
inner join sys.tables on schemas.schema_id = tables.schema_id
open tbl_cursor
fetch next from tbl_cursor
into @stat
while @@FETCH_STATUS = 0
begin
exec sp_executesql @statement = @stat
fetch next from tbl_cursor
into @stat
end
close tbl_cursor
deallocate tbl_cursor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment