版主你好

Ivin 2003-05-13 05:07:22
版主你好。
各位来了的朋友你们也好。
帮帮忙。
现有状况如下:
在一台SQL Server上有接近700张表,都含有 “ 字段1 (关键字段)”, 表如下:
-------------------------------------------------------------------
字段1 (关键字段) | 字段2 | 。。。。。
-------------------------------------------------------------------
A | ... |
-------------------------------------------------------------------

现想更改 “字段1 (关键字段)”下A的值,

更新对照表如下:
-------------------------------------------------------------------
旧值 | 新值 |
-------------------------------------------------------------------
A | a |
-------------------------------------------------------------------

应该如何同时更新这700张表,提个醒:A 是关键字段。

菜鸟求救。
...全文
28 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
愉快的登山者 2003-05-15
  • 打赏
  • 举报
回复
select b.name, identity(int,1,1) id into #t from syscolumns A, sysobjects B
where A.id = B.id and B.type = 'u'
and a.name = '字段1'
declare @i int
declare @s varchar(300)
declare @n varchar(100)
set @i = 1
while exists (select * from #t where id = @i)
begin
select @n = name from #t where id = @i
set @s = 'update ' + @n + ' set 字段1 = "a" where 字段1 = "A"'
exec (@s)
set @i = @i + 1
end
drop table #t
wgy2008 2003-05-15
  • 打赏
  • 举报
回复
delcare @name char(100)
declare cursor cur_kk for
select name
from sysobjects
where xtype = 'u'
open cur_KK
fetch cur_kk into @name
while @@fetch_status = 0
begin
update @name
set 字段1='a'
fetch cur_kk into @name
end
close cur_kk

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧