在多个表中查询某个字段的问题

leezm 2003-11-12 10:03:19
在工作的过程中遇到这样一个头痛的问题:

有A,B,C三个数据库,每个数据库分别有十几个表如:A_T1,A_T2,A_T3...;
B_T1,B_T2,B_T3...;C_T1,C_T2,C_T3...等;

有一个字段Com_name存在于这些数据库中的多个表中,在有些表中有,有些表中没有该字段。

现在的问题是由于没有具体的数据库的关系结构,请问如何可以查询到Com_name字段存在于哪些表中?或者可以直接从这些表中updata Com_name字段.

先谢谢各位热心人了,希望各位都考虑一下解决的办法。
...全文
128 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
leezm 2003-11-12
  • 打赏
  • 举报
回复
大力哥,能写点注解吗?小弟刚学没有经验呀
txlicenhe 2003-11-12
  • 打赏
  • 举报
回复
select name from syscolumns where name = 'Com_name'

shuiniu 2003-11-12
  • 打赏
  • 举报
回复
select b.name 表名,a.name 字段名 from A..syscolumns a, A..sysobjects b where a.name = 'Com_name' and a.id = b.id
select b.name 表名,a.name 字段名 from B..syscolumns a, B..sysobjects b where a.name = 'Com_name' and a.id = b.id
select b.name 表名,a.name 字段名 from C..syscolumns a, C..sysobjects b where a.name = 'Com_name' and a.id = b.id
pengdali 2003-11-12
  • 打赏
  • 举报
回复
declare cursor1 cursor for select d.name from syscolumns a, sysobjects d where a.id=d.id and d.xtype='U' and a.name='Com_name'
declare
@i varchar(1000)
open cursor1
fetch cursor1 into @i
while @@fetch_status=0
begin
exec('update '+@i+' set Com_name=''人事处'' where Com_name=''人事管理部''')
fetch cursor1 into @i
end
close cursor1
deallocate cursor1

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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