检查存储过程,视图,函数,列是否存在
--判断存储过程是否存在
if exists(select * from sysobjects where id=object_id('[dbo].[存储过程名]') and xtype='P')
DROP PROCEDURE [dbo].[存储过程名]
GO
--判断视图是否存在
if exists(select * from sysobjects where name= '视图名' AND type = 'v ')
DROP VIEW [dbo].[视图名]
GO
--判断睡自定义函数是否存在
IF OBJECT_ID (N'[函数名]') IS NOT NULL
drop function [dbo].[函数名]
GO
--判断列是否存在
if not exists(select name from syscolumns where name='列名' and
id in (select id from sysobjects where name='表名' and type='u'))
BEGIN
--添加列操作
END
--判断表是否存在
if exists (select 1
from sysobjects
where id = object_id('表名')
and type = 'U')
drop table 表名
go

浙公网安备 33010602011771号