读书人

object_id与select * from dbo.sysobj

发布时间: 2012-09-03 09:48:39 作者: rapoo

object_id与select * from dbo.sysobjects where id = object_id的区别

SQL code
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[fn_test]'))begin   select 1end if object_id(N'[dbo].[fn_test]') is  not  nullbegin   select 2end 

请问这个2句sql语句(object_id)和 (select * from dbo.sysobjects where id = object_id(。。。))这个有区别吗

[解决办法]
判断的时候最好加一个type的限定,指定对象是表 函数 存储过程等,如果有相同名字,例如有fn_test的表及存储过程,那么这个判断不是很准确。

读书人网 >SQL Server

热点推荐