---Name: 插入/更新 列模板.sql
---Purpose: 用于更新 数据库中 列 的脚本模板
---Author: xx
---Time: 2015-12-18 10:26:06
---Remark: tb_simple 为要更新的表;cloumn_simple 为要更新的列,id 为主键

BEGIN TRANSACTION 
DECLARE @errorSun INT  
SET @errorSun=0  


if exists (select * from syscolumns where id=object_id('tb_simple') and name='cloumn_simple')
begin
--execute(' alter table tb_simple drop column cloumn_simple ')
--SET @errorSun=@errorSun+@@ERROR  
print ' cloumn cloumn_simple exist!'
end

else
begin
alter table tb_simple add cloumn_simple int null
SET @errorSun=@errorSun+@@ERROR  
print 'add cloumn cloumn_simple ok'
end

IF @errorSun<>0
BEGIN
PRINT '有错误,回滚'
ROLLBACK TRANSACTION 
END

ELSE
BEGIN
PRINT '成功,提交'
COMMIT TRANSACTION 
END

 

posted on 2017-02-17 16:58  王庆东mas  阅读(222)  评论(0编辑  收藏  举报