2016年4月11日 星期一

檢查TABLE是否存在,若存在就DROP掉

IF EXISTS (SELECT * FROM sys.tables WHERE schema_id = '1' AND name = 'TableA')
DROP TABLE TableA
GO
--條件不加schema_id
if exists(select * from sys.tables where name = 'TableA') drop table TableA;
--以下語法要SQL Server 2016之後才支援
drop table if exists TableA;

沒有留言:

張貼留言