如果所有表中的值和列匹配,则更新数据

时间:2014-09-12 09:03:20

标签: sql database select toad rdms

我在更新名为' ST_CODE'的列中的值时遇到问题。存在于整个数据库的许多表中。

我能够找到包含列" ST_CODE"的表格。使用以下代码。

SELECT c.name As ColNames, t.name as TableNames 
FROM sys.columns c JOIN sys.tables t ON c.object_id = t.object_id 
WHERE c.name='ST_CODE'

是否可以更新&00; 00000'至 11000'对于名为' ST_CODE'的所有列在所有表格中?

非常感谢!

1 个答案:

答案 0 :(得分:0)

是..创建存储过程并将您的表名和列名插入临时表中。

  Insert into #temp(SELECT c.name As ColNames, t.name as TableNames 
  FROM sys.columns c JOIN sys.tables t ON c.object_id = t.object_id 
  WHERE c.name='ST_CODE')

然后循环临时表并根据需要编写更新语句。请点击此链接获取帮助。 http://ask.sqlservercentral.com/questions/24259/how-to-update-a-dynamic-sql-table-with-a-set-varia.html

相关问题