forked from bulentgucuk/DBA-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDrop Procs Functions Schemas.sql
170 lines (146 loc) · 3.21 KB
/
Drop Procs Functions Schemas.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
-- drop all the type of functions
declare @cnt int,
@sql Varchar(1000),
@rowcount int
create table #test (
id int identity,
line Varchar(1000)
)
insert into #test(line)
select 'drop function ' +
quotename(schema_name(schema_id)) + '.' +
quotename(name)
from sys.objects
where type = 'tf' -- table valued funciont
or type = 'if' -- inline function
or type = 'af' -- aggregate function (clr)
or type = 'fn' -- scalar function
order by name
select @rowcount = @@rowcount
select @cnt = 1
while @rowcount > = @cnt
begin
select @sql = line from #test where id = @cnt
print @sql
exec (@sql)
select @cnt= @cnt+ 1
end
drop table #test
go
-- drop all the stored procedures
declare @cnt int,
@sql Varchar(1000),
@rowcount int
create table #test (
id int identity,
line Varchar(1000)
)
insert into #test(line)
select 'drop procedure ' +
QUOTENAME(schema_name(schema_id)) + '.' +
QUOTENAME(name)
from sys.procedures
where is_ms_shipped = 0
and name != 'sp_whoisactive'
and name != 'sp_who3'
order by name
select @rowcount = @@rowcount
select @cnt = 1
while @rowcount > = @cnt
begin
select @sql = line from #test where id = @cnt
print @sql
exec (@sql)
select @cnt= @cnt+ 1
end
drop table #test
go
-- drop all the synonyms
declare @cnt int,
@sql Varchar(1000),
@rowcount int
create table #test (
id int identity,
line Varchar(1000)
)
insert into #test(line)
select 'drop synonym ' +
QUOTENAME(schema_name(schema_id)) + '.' +
QUOTENAME(name)
from sys.synonyms
where is_ms_shipped = 0
order by name
select @rowcount = @@rowcount
select @cnt = 1
while @rowcount > = @cnt
begin
select @sql = line from #test where id = @cnt
print @sql
exec (@sql)
select @cnt= @cnt+ 1
end
drop table #test
go
-- drop all the xml schema collections
declare @cnt int,
@sql Varchar(1000),
@rowcount int
create table #test (
id int identity,
line Varchar(1000)
)
insert into #test(line)
select 'drop xml schema collection ' +
QUOTENAME(schema_name(schema_id)) + '.' +
QUOTENAME(name)
from sys.xml_schema_collections
where name != 'sys'
select @rowcount = @@rowcount
select @cnt = 1
while @rowcount > = @cnt
begin
select @sql = line from #test where id = @cnt
print @sql
exec (@sql)
select @cnt= @cnt+ 1
end
drop table #test
go
-- drop all the schemas
declare @cnt int,
@sql Varchar(1000),
@rowcount int
create table #test (
id int identity,
line Varchar(1000)
)
insert into #test(line)
select 'drop schema ' +
QUOTENAME(name)
from sys.schemas
where name in (
'SalesLT',
'HumanResources',
'Person',
'Production',
'Purchasing',
'Sales',
'MetadataSchema'
)
select @rowcount = @@rowcount
select @cnt = 1
while @rowcount > = @cnt
begin
select @sql = line from #test where id = @cnt
print @sql
exec (@sql)
select @cnt= @cnt+ 1
end
drop table #test
go
IF EXISTS (SELECT * FROM sys.triggers WHERE parent_class_desc = 'DATABASE' AND name = N'ddlDatabaseTriggerLog')
DISABLE TRIGGER [ddlDatabaseTriggerLog] ON DATABASE
GO
/****** Object: DdlTrigger [ddlDatabaseTriggerLog] Script Date: 10/02/2012 13:33:32 ******/
IF EXISTS (SELECT * FROM sys.triggers WHERE parent_class_desc = 'DATABASE' AND name = N'ddlDatabaseTriggerLog')DROP TRIGGER [ddlDatabaseTriggerLog] ON DATABASE
GO