将记录从一个数据库更新到另一个数据库 [英] Update records from One database to another database
本文介绍了将记录从一个数据库更新到另一个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨..朋友,
我有两个数据库,定义相同。如果在第一个数据库表的记录中发生任何更改,我还想更新第二个数据库表的记录。我想为此写一个查询。请帮帮我..
Hi..Friends,
I have two database with same definition. If any change happens in first database tables''s Records, I also want to update second database table''s Records. I want to write a query for this. Please help me..
推荐答案
请查看以下网址
http://channel9.msdn.com/(A(bHEwY2UNzQEkAAAAYmZmZGFkNjgtZTBlMS00ODFhLTg0NTctOWQ5NWYwMDkyNjQ0u5Xc2R8J08gHEBVo58ddiNUwFTk1))/论坛/ TechOff / 176509-UPDATE-one-table-from-a-table-in-another-database [ ^ ]
Please check below url
http://channel9.msdn.com/(A(bHEwY2UNzQEkAAAAYmZmZGFkNjgtZTBlMS00ODFhLTg0NTctOWQ5NWYwMDkyNjQ0u5Xc2R8J08gHEBVo58ddiNUwFTk1))/Forums/TechOff/176509-UPDATE-one-table-from-a-table-in-another-database[^]
你可以在特定的桌子上使用Trigger来做这件事..
ex:
Hi,
You can do this using Trigger on the particular table..
ex:
CREATE TRIGGER trg_YourTrigger ON dbo.AA
FOR UPDATE
AS
UPDATE B.dbo.BB
SET ColumnY = I.ColumnX
FROM inserted I
INNER JOIN
deleted D
ON I.PrimaryKeyInTableAA = D.PrimaryKeyInTableAA
WHERE B.dbo.BB.ColumnY = D.ColumnX
<pre lang="SQL">
最简单的方法是使用(第一次):
The simplest way is to use (for the first time):
INSERT INTO [destination database].[dbo].[destination table] ([destination field1], [destination field12], [destination fieldN])
SELECT ([source field1], [source field12], [source fieldN])
FROM [source database].[dbo].[source table]
下次,你需要使用更新 [ ^ ]声明。
更多: INSERT示例(Transact-SQL) [ ^ ]
SELECT语句(T-SQL) [ ^ ]
Next time, you''ll need to use UPDATE[^] statement.
More: INSERT Examples (Transact-SQL)[^]
SELECT statement (T-SQL)[^]
这篇关于将记录从一个数据库更新到另一个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文