Skip to content

Instantly share code, notes, and snippets.

@sdurandeu
Created March 14, 2014 21:41
Show Gist options
  • Save sdurandeu/9557582 to your computer and use it in GitHub Desktop.
Save sdurandeu/9557582 to your computer and use it in GitHub Desktop.
Empty a TeamCity database
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