· 7 years ago · Sep 22, 2018, 10:02 PM
1use tempdb
2go
3
4--------------------------------------------------------------------------------
5-- creates the table
6--------------------------------------------------------------------------------
7
8if exists (
9 select *
10 from sys.tables t
11 inner join sys.schemas s
12 on t.schema_id = s.schema_id
13 where t.name = 't1'
14 and s.name ='dbo'
15 )
16 begin
17
18 drop table dbo.t1
19 print 'table dropped'
20 end
21else
22 begin
23
24 create table dbo.t1 (i int not null primary key clustered)
25 print 'table created'
26 end
27go
28
29--------------------------------------------------------------------------------
30-- drops the table
31--------------------------------------------------------------------------------
32
33if exists (
34 select *
35 from sys.tables t
36 inner join sys.schemas s
37 on t.schema_id = s.schema_id
38 where t.name = 't1'
39 and s.name ='dbo'
40 )
41 begin
42
43 drop table dbo.t1
44 print 'table dropped'
45 end
46else
47 begin
48
49 create table dbo.t1 (i int not null primary key clustered)
50 print 'table created'
51 end
52go
53
54SELECT object_schema_name(object_id), name
55FROM sys.objects
56WHERE name = 'table_name'