T-SQL 如何判断表是否存在并删除它
- 物理表
IF OBJECT_ID('dbo.Scores', 'U') IS NOT NULL DROP TABLE dbo.Scores;
- 临时表
IF OBJECT_ID('tempdb.dbo.#T', 'U') IS NOT NULL DROP TABLE #T;
- SQL Server 2016 新加功能
DROP TABLE IF EXISTS dbo.Scores
IF OBJECT_ID('dbo.Scores', 'U') IS NOT NULL DROP TABLE dbo.Scores;
IF OBJECT_ID('tempdb.dbo.#T', 'U') IS NOT NULL DROP TABLE #T;
DROP TABLE IF EXISTS dbo.Scores