Drop table if already exists in SQLServer. It is good Practice to keep this command before any create table script.
Type 1
IF EXISTS(SELECT * FROM dbo.test)
DROP TABLE dbo.test;
Type 2
IF OBJECT_ID('dbo.test', 'U') IS NOT NULL
DROP TABLE dbo.test;
Type 3
IF exists (select * from INFORMATION_SCHEMA.TABLES where TABLE_NAME = 'test' AND TABLE_SCHEMA = 'dbo')
Drop table dbo.test;
No comments:
Post a Comment