how to sync the data of two table?
-
suppose i have two table table1 & table2. now how can i sync the data of two table of sql server using microsoft sync frame work or using any other class.
tbhattacharjee
-
suppose i have two table table1 & table2. now how can i sync the data of two table of sql server using microsoft sync frame work or using any other class.
tbhattacharjee
You can use "Instead Of" or "After" triggers on those tables for Insert, Update and Delete actions. For example:
USE YourDatabase CREATE TRIGGER Table1_AfterDelete ON Table1 AFTER DELETE AS DELETE Table2 WHERE Table2.Id IN (SELECT Id FROM DELETED) GO CREATE TRIGGER Table1_AfterInsert ON Table1 AFTER INSERT AS INSERT INTO Table2 SELECT * FROM INSERTED GO CREATE TRIGGER Table1_AfterUpdate ON Table1 AFTER UPDATE AS UPDATE Table2 SET Table2.FirstName=Table1.FirstName, Table2.LastName=Table1.LastName FROM Table2 JOIN Table1 ON Table2.Id=Table1.Id GO
-
suppose i have two table table1 & table2. now how can i sync the data of two table of sql server using microsoft sync frame work or using any other class.
tbhattacharjee
While stonehearts answer is technically correct, I would question your data structure if you are storing the same data in 2 tables. I suggest you do some research into normalising your database (said with absolutely no knowledge of your data structure). Besides triggers are EVIL and should be avoided unless they are essential.
Never underestimate the power of human stupidity RAH