笔记99 查询某张表的objectid objectname OBJECT_NAME(objectid) OBJECT_ID('表名') 判断表是否存在
笔记99 查询某张表的objectid objectname OBJECT_NAME(objectid) OBJECT_ID('表名') 判断表是否存在
1 --查询某张表的objectid objectname OBJECT_NAME(objectid) OBJECT_ID('表名') 判断表是否存在 2 3 USE [GPOSDB] --要查询的那张表的所属数据库 4 SELECT OBJECT_NAME(OBJECT_ID('systempara')) 5 SELECT OBJECT_ID('systempara') 6 7 -------------------------------------------------------------------------- 8 --判断表是否存在 9 USE [GPOSDB] 10 IF OBJECT_ID('systempara') IS NOT NULL 11 PRINT 'systempara表存在' 12 --DROP TABLE [dbo].[SystemPara] 13 GO 14 15 16 ------------------------------------------------------------------------------ 17 USE [tempdb] 18 CREATE TABLE #t(id INT IDENTITY(1,1) NOT NULL) 19 20 USE [tempdb] 21 IF OBJECT_ID('#t') IS NOT NULL 22 DROP TABLE [#t] 23 GO 24 25 SELECT * FROM [#t]