-- check if table exists
if exists (select * from dbo.sysobjects where id = object_id(N'[TableName]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
-- do something
GO
-- check if view exists
if exists (select * from dbo.sysobjects where id = object_id(N'[ViewName]') and OBJECTPROPERTY(id, N'IsView') = 1)
-- do something
GO
-- check if stored procedure exists
if exists (select * from dbo.sysobjects where id = object_id(N'[StoredProcedureName]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
-- do something
GO
Comments
Post a Comment