Created
April 14, 2013 12:59
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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