Drop a table if necessary : Drop Table « Table « SQL Server / T-SQL






Drop a table if necessary


1>
2> CREATE TABLE department(dept_no   CHAR(4) NOT NULL,
3>                         dept_name CHAR(25) NOT NULL,
4>                         location  CHAR(30) NULL)
5> GO
1>
2> insert into department values ('d1', 'developer',   'Dallas')
3> insert into department values ('d2', 'tester',      'Seattle')
4> insert into department values ('d3', 'marketing',  'Dallas')
5> GO

(1 rows affected)

(1 rows affected)

(1 rows affected)
1>
2> select * from department
3> GO
dept_no dept_name                 location
------- ------------------------- ------------------------------
d1      developer                 Dallas
d2      tester                    Seattle
d3      marketing                 Dallas

(3 rows affected)
1>
2> drop table department
3> GO
1>
           
       








Related examples in the same category

1.A statement that qualifies the table to be deleted
2.If table exists, rename and create new one