Created
March 14, 2014 21:41
-
-
Save sdurandeu/9557582 to your computer and use it in GitHub Desktop.
Empty a TeamCity database
This file contains 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 @name VARCHAR(128) | |
DECLARE @SQL VARCHAR(254) | |
DECLARE @schema VARCHAR(128) | |
SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'U' AND category = 0 ORDER BY [name]) | |
SELECT @schema = (SELECT TOP 1 schema_name(schema_id) FROM sys.tables WHERE [name] = @name) | |
WHILE @name IS NOT NULL | |
BEGIN | |
SELECT @SQL = 'DROP TABLE [' + @schema + '].[' + RTRIM(@name) +']' | |
EXEC (@SQL) | |
PRINT 'Dropped Table: ' + @name | |
SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'U' AND category = 0 AND [name] > @name ORDER BY [name]) | |
SELECT @schema = (SELECT TOP 1 schema_name(schema_id) FROM sys.tables WHERE [name] = @name) | |
END | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment