1.判断某个存储过程是否存在
if exists(select 1 from sysobjects where name = 'XXXXXX' and xtype = 'P')
begin
drop proc XXXXXX
end
go
2.判断某张表是否存在
if not Exists(select 1 from sysObjects where Id=OBJECT_ID(N'XXXXXX') and xtype='U')
3.判断某个视图是否存在
if exists(select 1 from sysobjects where name = 'XXXXXX' and xtype = 'V')
BEGIN
drop view XXXXXX
END
GO
4.判断表中某一列是否存在,若不存在则添加
IF NOT EXISTS(SELECT 1 FROM syscolumns WHERE id=OBJECT_ID('XXXXXX') AND NAME='XXXXXX')
ALTER TABLE XXXXXX ADD XXXXXX varchar(100)
GO