forked from bulentgucuk/DBA-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDrop Views and Tables.sql
More file actions
58 lines (49 loc) · 995 Bytes
/
Drop Views and Tables.sql
File metadata and controls
58 lines (49 loc) · 995 Bytes
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
-- drop all the views
declare @cnt int,
@sql Varchar(1000),
@rowcount int
create table #test (
id int identity,
line Varchar(1000)
)
insert into #test(line)
select 'drop view ' +
QUOTENAME(SCHEMA_NAME(schema_id)) + '.' +
QUOTENAME(name)
from sys.views
where is_ms_shipped = 0
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 tables
declare @cnt int,
@sql Varchar(1000),
@rowcount int
create table #test (
id int identity,
line Varchar(1000)
)
insert into #test(line)
select 'drop table ' +
QUOTENAME(SCHEMA_NAME(schema_id)) + '.' +
QUOTENAME(name)
from sys.tables
where is_ms_shipped = 0
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