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. Database & SysAdmin
  3. Database
  4. TSql , Update master / child records

TSql , Update master / child records

Scheduled Pinned Locked Moved Database
databasesql-serversalesannouncement
5 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.
  • H Offline
    H Offline
    Hemant Thaker
    wrote on last edited by
    #1

    Hi.. I have the scene like this.... I have one master table say Users(userid, pwd) and child table customer(userid,name,address) both tables are related with field 'userid'. Now customer wants to update his userid. so userid will be updated in master as well as child record. could u suggest me the update query for this without deleting and inserting the records. thanks, Hemant

    A M 2 Replies Last reply
    0
    • H Hemant Thaker

      Hi.. I have the scene like this.... I have one master table say Users(userid, pwd) and child table customer(userid,name,address) both tables are related with field 'userid'. Now customer wants to update his userid. so userid will be updated in master as well as child record. could u suggest me the update query for this without deleting and inserting the records. thanks, Hemant

      A Offline
      A Offline
      Ashfield
      wrote on last edited by
      #2

      Your basic design is wrong, the userid should not be significant and should not be the primary key if it can be changed. However, if this is an existing system which you cannot change then simply do the update to both tables within a single transaction - assuming you do not have a foreign key constraint.

      Bob Ashfield Consultants Ltd

      H 2 Replies Last reply
      0
      • A Ashfield

        Your basic design is wrong, the userid should not be significant and should not be the primary key if it can be changed. However, if this is an existing system which you cannot change then simply do the update to both tables within a single transaction - assuming you do not have a foreign key constraint.

        Bob Ashfield Consultants Ltd

        H Offline
        H Offline
        Hemant Thaker
        wrote on last edited by
        #3

        thanks for reply, i do have foreign key which is userid in customer table. will it be possible to write a single statement for update. could u guide., thanks

        By: Hemant Thaker

        1 Reply Last reply
        0
        • A Ashfield

          Your basic design is wrong, the userid should not be significant and should not be the primary key if it can be changed. However, if this is an existing system which you cannot change then simply do the update to both tables within a single transaction - assuming you do not have a foreign key constraint.

          Bob Ashfield Consultants Ltd

          H Offline
          H Offline
          Hemant Thaker
          wrote on last edited by
          #4

          I think on update cascade will work here, what do u say ? thanks

          By: Hemant Thaker

          1 Reply Last reply
          0
          • H Hemant Thaker

            Hi.. I have the scene like this.... I have one master table say Users(userid, pwd) and child table customer(userid,name,address) both tables are related with field 'userid'. Now customer wants to update his userid. so userid will be updated in master as well as child record. could u suggest me the update query for this without deleting and inserting the records. thanks, Hemant

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

            You should immediately remedy the primary key issue if you have control of the database. I would add an identity field UserNo to user table and the appropriate fields and keys to the FK table(s). As Bob said you have made a fundamental error in data design, fix it and you no longer have the update problem.

            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