SQL学习之查询技巧 查询表是否存在的两种方法 方法一 判断系统对象是否存在 DECLARE @DbTableFileName VARCHAR(100) SET @DbTableFileName = 'tx' IF objectproperty(object_id(@DbTableFileName),'IsUserTable') IS NOT NULL PRINT 'EXISTS ' ELSE PRINT 'NOT EXISTS ' IF object_id(@DbTableFileName) IS NOT NULL PRINT 'EXISTS ' ELSE PRINT 'NOT EXISTS ' IF EXISTS (SELECT Object_id(@DbTableFileName)) PRINT 'EXISTS ' ELSE PRINT 'NOT EXISTS ' 方法二 通过查询系统表 DECLARE @DbTableFileName VARCHAR(100) SET @DbTableFileName = 'tx' IF EXISTS (SELECT 1 FROM sysobjects WHERE name = @DbTableFileName AND TYPE = 'u') PRINT 'EXISTS ' ELSE PRINT 'NOT EXISTS ' 方法一更安全,