62,268
社区成员
发帖
与我相关
我的任务
分享
/*
funcation:将某数据库中所有表中的某个具体的字段修改为某值
exec updateTable '名称','文燕专'
create by:文燕专
date:2009-4-9
*/
create procedure updateTable
@colName nvarchar(20),
@colValue nvarchar(20)
as
begin
declare cur cursor for
select name from sysobjects where type = 'u'
declare @name nvarchar(20)
open cur
fetch next from cur into @name
while @@fetch_status =0
begin
if exists(select 1 from syscolumns where id = (select id from sysobjects where type = 'u' and name = @name) and name=@colName)
begin
declare @sql nvarchar(4000)
set @sql = ''
set @sql = 'update ' + @name + ' set ' + @colName + ' = ''' + @colValue + ''''
exec(@sql)
end
fetch next from cur into @name
end
close cur
deallocate cur
end