Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. how to sync the data of two table?

how to sync the data of two table?

Scheduled Pinned Locked Moved C#
questiondatabasesql-serversysadmintutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tridip Bhattacharjee
    wrote on last edited by
    #1

    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

    X M 2 Replies Last reply
    0
    • T Tridip Bhattacharjee

      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

      X Offline
      X Offline
      xstoneheartx
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • T Tridip Bhattacharjee

        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

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups