日期:2014-05-17  浏览次数:20391 次

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 1
end 

if object_id(N'[dbo].[fn_test]') is  not  null
begin
   select 2
end 

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

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