判定資料表是否存在:
if exists (select * from sysobjects where id = object_id(N'[dbo].[mytable]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
或
if exists (select * from sysobjects where id = object_id('mytable') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
判定物件屬性:
以下範例測試 authors 是否為資料表。
IF OBJECTPROPERTY ( object_id('authors'),'ISTABLE') = 1
print 'Authors is a table'
ELSE IF OBJECTPROPERTY ( object_id('authors'),'ISTABLE') = 0
print 'Authors is not a table'
ELSE IF OBJECTPROPERTY ( object_id('authors'),'ISTABLE') IS NULL
print 'ERROR: Authors is not an object'