Real-time data synchronization between two database tables

Source: Internet
Author: User
Welcome to the Windows community forum and interact with 3 million technical staff to access the ****** Object: Trigger [dbo]. [TR_C0T14] ScriptDate: 1101201113: 21: 04 ****** SETANSI_NULLSONGOSETQUOTED_IDENTIFIERONGO ――

Welcome to the Windows community forum and interact with 3 million technical staff> go to/****** Object: Trigger [dbo]. [TR_C0T14] Script Date: 11/01/2011 13:21:04 ******/SET ANSI_NULLS on go set QUOTED_IDENTIFIER on go ============== ======================================

Welcome to the Windows community forum and interact with 3 million technicians>

/***** Object: Trigger [dbo]. [TR_C0T14] Script Date: 11/01/2011 13:21:04 ******/SET ANSI_NULLS on go set QUOTED_IDENTIFIER ON GO

---= =======-- Author: -- Create date: <2011-11-01>-Description: <两个数据库表数据实时同步> ---= ========

-- Drop trigger TR_C0T14

Create trigger [dbo]. [TR_C0T14] ON [dbo]. [C0T14] for insert, UPDATE, delete as begin if not exists (SELECT * FROM deleted)

BEGIN/* INSERT */insert into leamon_test ...... C0T14 (RATINGID, [BROKER], BROKERRATE, SFRATE, SFVALUE, F_OP1, F_OP2, F_OPC1, F_OPC2, F_9997, f_9998)

Select ratingid, [BROKER], BROKERRATE, SFRATE, SFVALUE, F_OP1, F_OP2, F_OPC1, F_OPC2, F_9997, f_9998 FROM inserted where not exists (select top 1 * FROM leamon_test ...... C0T14 WHERE inserted. RATINGID = leamon_test ...... C0T14. RATINGID)

END/* Delete */else if not exists (SELECT * FROM inserted)

Delete from leamon_test ...... C0T14 where ratingid in (select ratingid from deleted)

/* UPDATE */else begin update leamon_test ...... C0T14 set ratingid = inserted. RATINGID, [BROKER] = inserted. [BROKER], BROKERRATE = inserted. BROKERRATE, SFRATE = inserted. SFRATE, SFVALUE = inserted. SFVALUE, F_OP1 = inserted. f_OP1, F_OP2 = inserted. f_OP2, F_OPC1 = inserted. f_OPC1, F_OPC2 = inserted. f_OPC2, F_9997 = inserted. f_9997, f_9998 = inserted. f_9998 FROM inserted WHERE inserted. RATINGID = leamon_test ...... C0T14. ratingid and (inserted. [BROKER] <> leamon_test ...... C0T14. [BROKER] OR inserted. BROKERRATE <> leamon_test ...... C0T14. brokerrate or inserted. SFRATE <> leamon_test ...... C0T14. sfrate or inserted. SFVALUE <> leamon_test ...... C0T14. sfvalue or inserted. F_OP1 <> leamon_test ...... C0T14. F_OP1 OR inserted. F_OP2 <> leamon_test ...... C0T14. F_OP2 OR inserted. F_OPC1 <> leamon_test ...... C0T14. F_OPC1 OR inserted. F_OPC2 <> leamon_test ...... C0T14. F_OPC2 OR inserted. F_9997 <> leamon_test ...... C0T14. F_9997 OR inserted. f_9998 <> leamon_test ...... C0T14. f_9998)

END

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.