我有一个庞大的数据库,需要一个查询来更新数据库中的不同表。我相信这应该很容易,因为我正在改变的列在每个表中是相同的。这是我到目前为止所拥有的;
UPDATE a_assets,
client_notes,
client_pending,
client_task,
country,
document_log,
favlists,
favourites,
g_address,
g_climst,
g_dialog,
g_lang,
g_prdmst,
g_secure,
j_alloc,
logger,
passhistory,
portfolios,
prod_metrics_tank,
product_usage_lists,
region,
reasearch_logger,
search_dataphile,
search_esg,
search_rpm,
sql_workout,
universe_source,
user_jurisdications,
user_languages,
user_universe,
work_group_mappings,
work_groups,
spt_docs
set a_assets.planner = ? ,
client_notes.planner = ?,
client_pending.planner = ?,
client_task.planner = ?,
country.planner = ?,
document_log.planner=?,
favlists.planner=?,
favourites.planner=?,
g_address.planner = ?,
g_climst.planner =?,
g_dialog.planner=?,
g_lang.planner=?,
g_prdmst.planner=?,
j_alloc.planner=?,
logger.planner=?,
passhistory.planner=?,
portfolios.planner=?,
prod_metrics_tank.planner=?,
product_usage_lists.planner=?,
region.planner=?,
reasearch_logger.planner=?,
search_dataphile.planner=?,
search_esg.planner=?,
search_rpm.planner=?,
sql_workout.planner=?,
universe_source.planner=?,
user_jurisdications.planner=?,
user_languages.planner=?,
user_universe.planner=?,
work_group_mappings.planner=?,
work_groups.planner=?,
spt_docs.planner=?,
g_secure.planner = ?
where a_assets.planner = ? ,
client_notes.planner = ?,
client_pending.planner = ?,
client_task.planner = ?,
country.planner = ?,
document_log.planner=?,
favlists.planner=?,
favourites.planner=?,
g_address.planner = ?,
g_climst.planner =?,
g_dialog.planner=?,
g_lang.planner=?,
g_prdmst.planner=?,
g_secure.planner = ?,
j_alloc.planner=?,
logger.planner=?,
passhistory.planner=?,
portfolios.planner=?,
prod_metrics_tank.planner=?,
product_usage_lists.planner=?,
region.planner=?,
reasearch_logger.planner=?,
search_dataphile.planner=?,
search_esg.planner=?,
search_rpm.planner=?,
sql_workout.planner=?,
universe_source.planner=?,
user_jurisdications.planner=?,
user_languages.planner=?,
user_universe.planner=?,
work_group_mappings.planner=?,
work_groups.planner=?,
spt_docs.planner=?
我不确定为什么这不会起作用,因为所有表都在更新他们的计划列。当这个运行时,我得到一个:ILLEGAL SYMBOL“令牌”。一些可能是法律的符号是:令牌列表。
查询中需要更改的内容才能使所有表都使用相同的数据进行更新。
答案 0 :(得分:0)
您无法在单个更新语句中更新多个表。 [Update multiple tables in SQL Server using INNER JOIN
答案 1 :(得分:0)
为什么要在一个语句中更新所有表?假设您使用的是最新版本的LUW,您实际上可以通过转换表和cte根据以下内容进行更新:
with t1 (n) as ( select count(1)
from new table (
update a_assets
set planer = ?
where planer = ?
)
)
, t2 (n) as ( ...
)
, ...
, tn (n) as ( ...
)
select n from t1
union all
select n from t2
...
select n from tn
但我怀疑这不是你想要的。
我建议您创建一个循环遍历表的过程,然后使用execute immediate来触发语句