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. SQL 2005

SQL 2005

Scheduled Pinned Locked Moved Database
questiondatabase
7 Posts 5 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.
  • L Offline
    L Offline
    lyngocquy
    wrote on last edited by
    #1

    i have two tables ROOM(nbROOM primary key) : ML002 STUDENT(nbROOM) : ML002 How can i change the ROOM(nbROMM) : ML002 => ML003 =========> the STUDENT(nbROOM) must also change : ML002 =>ML003 ?:confused:

    J A L 3 Replies Last reply
    0
    • L lyngocquy

      i have two tables ROOM(nbROOM primary key) : ML002 STUDENT(nbROOM) : ML002 How can i change the ROOM(nbROMM) : ML002 => ML003 =========> the STUDENT(nbROOM) must also change : ML002 =>ML003 ?:confused:

      J Offline
      J Offline
      jschell
      wrote on last edited by
      #2

      Simple - you can't. The first problem is that you are using business data for keys. And you now know why that is a problem. Your only solution now requires. 1. Create a new room row with ML003 2. Update STUDENT to point to MLO03. 3. Delete the existing ML002 record. Second problem is that what you are doing isn't logical anyways. If you have a list of rooms you don't change them unless you are in fact relabeling all of the rooms themselves (ie someone is going down the hallway in the school and putting new numbers on the doors.) In contrast if a person is assigned to the wrong room or needs to be moved then you update the person, not the room, to indicate the change. (In databases in general there is another way to do this but it wouldn't apply to room assignment.) Your solution should be ROOM(primary key, room label): {1, ML002}, {2, ML003} STUDENT(room primary key): {1} In the above you would just update '1' in the student record to be a '2'

      L 1 Reply Last reply
      0
      • L lyngocquy

        i have two tables ROOM(nbROOM primary key) : ML002 STUDENT(nbROOM) : ML002 How can i change the ROOM(nbROMM) : ML002 => ML003 =========> the STUDENT(nbROOM) must also change : ML002 =>ML003 ?:confused:

        A Offline
        A Offline
        AspDotNetDev
        wrote on last edited by
        #3

        I am assuming you have a foreign key constraint that is preventing you from modifying the primary key. In that case, insert new records that are based on the existing records, but with the new primary key, then delete the old records.

        [Managing Your JavaScript Library in ASP.NET]

        1 Reply Last reply
        0
        • J jschell

          Simple - you can't. The first problem is that you are using business data for keys. And you now know why that is a problem. Your only solution now requires. 1. Create a new room row with ML003 2. Update STUDENT to point to MLO03. 3. Delete the existing ML002 record. Second problem is that what you are doing isn't logical anyways. If you have a list of rooms you don't change them unless you are in fact relabeling all of the rooms themselves (ie someone is going down the hallway in the school and putting new numbers on the doors.) In contrast if a person is assigned to the wrong room or needs to be moved then you update the person, not the room, to indicate the change. (In databases in general there is another way to do this but it wouldn't apply to room assignment.) Your solution should be ROOM(primary key, room label): {1, ML002}, {2, ML003} STUDENT(room primary key): {1} In the above you would just update '1' in the student record to be a '2'

          L Offline
          L Offline
          lyngocquy
          wrote on last edited by
          #4

          ^^~ u didn't understand my problem ROOM(nuROOM primary key, nameROOM) STUDENT(nuSTUDENT primary key,nameSTUDENT,nuROOM) :confused: this is my database !

          M J 2 Replies Last reply
          0
          • L lyngocquy

            i have two tables ROOM(nbROOM primary key) : ML002 STUDENT(nbROOM) : ML002 How can i change the ROOM(nbROMM) : ML002 => ML003 =========> the STUDENT(nbROOM) must also change : ML002 =>ML003 ?:confused:

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            It's called "cascade on update", and it's a bad habit. You'd really provide an artificial key to make the reference. It'd be wise to use an alternative unique constraint for the primary identification of the BO.

            Bastard Programmer from Hell :suss:

            1 Reply Last reply
            0
            • L lyngocquy

              ^^~ u didn't understand my problem ROOM(nuROOM primary key, nameROOM) STUDENT(nuSTUDENT primary key,nameSTUDENT,nuROOM) :confused: this is my database !

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

              What JSchell is saying is that your database is designed WRONG and you should fix it before you get into even more trouble. Whats more he gave you the ideas of how to fix it.

              Never underestimate the power of human stupidity RAH

              1 Reply Last reply
              0
              • L lyngocquy

                ^^~ u didn't understand my problem ROOM(nuROOM primary key, nameROOM) STUDENT(nuSTUDENT primary key,nameSTUDENT,nuROOM) :confused: this is my database !

                J Offline
                J Offline
                jschell
                wrote on last edited by
                #7

                lyngocquy wrote:

                u didn't understand my problem

                No you don't understand my reply. 1. Your database design is wrong. 2. This problem is a specific example of why it is wrong. 3. I told you how to do the update with your existing design.

                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