比较具有相同 Table 结构的两个数据库中的两个 Table
Compare Two Tables In two Databases with the same Table Structure
我有两个数据库 Database_1
和 Database_2
。这两个数据库的 table asset_table
具有相同的列和相同的 table 结构。但是 Database_2
asset_table
比 Database_1
asset_table
.
多了一些数据
我需要将“Database_2”中额外数据中的一些列更新为“0”。
这是我的更新查询。
Update Database_2.q2m1.asset_table
set min_qty = 0, max_qty = 0, unit_cost = '0.00'
我需要一个查询来检查 Database_2
中包含哪些额外数据而不是 Database_1
.
两个 table 的主键都是 asset_is
。然后更新数据。
谁能帮我写一个脚本?
我想你想要 not exists
:
update a2
set min_qty = 0, max_qty = 0, unit_cost = 0
from database2.asset_table a2
where not exists (
select 1 from database1.asset_table a1 where a1.asset_id = a2.asset_id
)
我有两个数据库 Database_1
和 Database_2
。这两个数据库的 table asset_table
具有相同的列和相同的 table 结构。但是 Database_2
asset_table
比 Database_1
asset_table
.
我需要将“Database_2”中额外数据中的一些列更新为“0”。
这是我的更新查询。
Update Database_2.q2m1.asset_table
set min_qty = 0, max_qty = 0, unit_cost = '0.00'
我需要一个查询来检查 Database_2
中包含哪些额外数据而不是 Database_1
.
两个 table 的主键都是 asset_is
。然后更新数据。
谁能帮我写一个脚本?
我想你想要 not exists
:
update a2
set min_qty = 0, max_qty = 0, unit_cost = 0
from database2.asset_table a2
where not exists (
select 1 from database1.asset_table a1 where a1.asset_id = a2.asset_id
)