Created
September 28, 2011 17:26
-
-
Save justinpitts/1248570 to your computer and use it in GitHub Desktop.
partial fragment to emit a "drop all objects in schema" statement in TSQL
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
WITH | |
TABLES AS ( select TABLE_SCHEMA, TABLE_NAME , case table_type when 'view' then 'view' else 'table' end as type from INFORMATION_SCHEMA.TABLES) | |
, procs as ( select ROUTINE_SCHEMA, routine_name, ROUTINE_TYPE from INFORMATION_SCHEMA.ROUTINES ) | |
, domains as (select DOMAIN_SCHEMA, DOMAIN_NAME, 'TYPE' as type, '[' + DOMAIN_SCHEMA + '].[' + DOMAIN_NAME + ']' as q_name from INFORMATION_SCHEMA.DOMAINS) | |
, c as ( select '[' + table_schema + '].[' + table_name + ']' as q_name, type from ( select * from tables union select * from procs ) a ) | |
select 'if object_id(''' + q_name + ''') is not null drop ' + type + ' ' + q_name +';' from c union select 'drop ' + type + ' ' + q_name +';' from domains |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Actually, as it stands, it emits drops for all table/view/proc/function/schemata in the current database