Last active
August 29, 2015 14:07
-
-
Save hoangitk/8517d672a8c8d0cad5a4 to your computer and use it in GitHub Desktop.
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
| IF(@@SERVERNAME = 'BS-DVP22\SQLEXPRESS') | |
| BEGIN | |
| USE [STD50_DEV_Sprint4]; | |
| declare @n char(1) | |
| set @n = char(10) | |
| declare @stmt nvarchar(max) | |
| -- procedures | |
| select @stmt = isnull( @stmt + @n, '' ) + | |
| 'drop procedure [' + schema_name(schema_id) + '].[' + name + ']' | |
| from sys.procedures | |
| -- check constraints | |
| select @stmt = isnull( @stmt + @n, '' ) + | |
| 'alter table [' + schema_name(schema_id) + '].[' + object_name( parent_object_id ) + '] drop constraint [' + name + ']' | |
| from sys.check_constraints | |
| -- functions | |
| select @stmt = isnull( @stmt + @n, '' ) + | |
| 'drop function [' + schema_name(schema_id) + '].[' + name + ']' | |
| from sys.objects | |
| where type in ( 'FN', 'IF', 'TF' ) | |
| -- views | |
| select @stmt = isnull( @stmt + @n, '' ) + | |
| 'drop view [' + schema_name(schema_id) + '].[' + name + ']' | |
| from sys.views | |
| -- foreign keys | |
| select @stmt = isnull( @stmt + @n, '' ) + | |
| 'alter table [' + schema_name(schema_id) + '].[' + object_name( parent_object_id ) + '] drop constraint [' + name + ']' | |
| from sys.foreign_keys | |
| -- tables | |
| select @stmt = isnull( @stmt + @n, '' ) + | |
| 'drop table [' + schema_name(schema_id) + '].[' + name + ']' | |
| from sys.tables | |
| -- user defined types | |
| select @stmt = isnull( @stmt + @n, '' ) + | |
| 'drop type [' + schema_name(schema_id) + '].[' + name + ']' | |
| from sys.types | |
| where is_user_defined = 1 | |
| exec sp_executesql @stmt | |
| END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment