--判断数据库是否存在
if exists(select * from master..sysdatabases where name=N‘库名‘)
print ‘Exist‘
else
print ‘Not Exist‘
--判断表是否存在
if object_id(N‘表名‘,N‘U‘) is not null
print ‘Exist‘
else
print ‘Not Exist‘
--判断临时表是否存在
If Object_Id(‘Tempdb.dbo.#临时表名‘) Is Not Null
print ‘Exist‘
Else
print ‘Not Exist‘
--判断存储过程是否存在
if exists (select * from dbo.sysobjects where id = object_id(N‘AddBatchRecord‘) and OBJECTPROPERTY(id, N‘IsProcedure‘) = 1)
print ‘Exist‘
else
print ‘Not Exist‘
-- 判断要创建的视图名是否存在
if exists (select * from dbo.sysobjects where id = object_id(N‘[dbo].[视图名]‘) and OBJECTPROPERTY(id, N‘IsView‘) = 1)
print ‘Exist‘
else
print ‘Not Exist‘