-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDrop Specific DB Objects.sql
76 lines (68 loc) · 2.23 KB
/
Drop Specific DB Objects.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
SELECT 'DROP ' + CASE type
WHEN 'fn' THEN
'FUNCTION'
WHEN 'P' THEN
'PROCEDURE'
WHEN 'U' THEN
'TABLE'
WHEN 'V' THEN
'VIEW'
WHEN 'TR' THEN
'TRIGGER'
WHEN 'F' THEN
'Constraint'
WHEN 'D' THEN
'Default'
WHEN 'PK' THEN
'PRIMARY KEY'
WHEN 'UQ' THEN
'UNIQE Constraint'
WHEN 'SO' THEN
'SEQUENCE'
END + ' ' + OBJECT_SCHEMA_NAME(object_id)+ '.' +
OBJECT_NAME(object_id),
type
FROM sys.objects
WHERE (
OBJECT_SCHEMA_NAME(object_id) NOT IN
(
SELECT SchemaName FROM gnd_egsys.tblSystem
)
AND OBJECT_SCHEMA_NAME(object_id) NOT IN
(
SELECT REPLACE(SchemaName, 'gnd', 'gnu')FROM gnd_egsys.tblSystem
)
)
AND OBJECT_SCHEMA_NAME(object_id) LIKE 'gn%'
AND OBJECT_SCHEMA_NAME(object_id)NOT LIKE '%med%'
AND OBJECT_SCHEMA_NAME(object_id)NOT LIKE 'gnp%'
ORDER BY type,
1
SELECT DISTINCT 'DROP ' + CASE type
WHEN 'fn' THEN
'FUNCTION'
WHEN 'P' THEN
'PROCEDURE'
WHEN 'U' THEN
'TABLE'
WHEN 'V' THEN
'VIEW'
WHEN 'TR' THEN
'TRIGGER'
WHEN 'F' THEN
'Constraint'
WHEN 'D' THEN
'Default'
WHEN 'PK' THEN
'PRIMARY KEY'
WHEN 'UQ' THEN
'UNIQE Constraint'
WHEN 'SO' THEN
'SEQUENCE'
END + ' ' + OBJECT_SCHEMA_NAME(object_id)+ '.' +
OBJECT_NAME(object_id) + ';',
type
FROM sys.objects so INNER JOIN sys.syscomments sc ON sc.id = so.object_id
WHERE sc.text LIKE '%SalesInvocie%'
ORDER BY type,
1