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. How to Sort this, Get Next Record ID when Many users inserting and different Districts

How to Sort this, Get Next Record ID when Many users inserting and different Districts

Scheduled Pinned Locked Moved Database
questiondatabasetoolshelptutorial
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.
  • R Offline
    R Offline
    Robymon
    wrote on last edited by
    #1

    Rec_ID Rec_Name Dist_ID 1 A 1 2 B 1 1 AA 2 2 AB 2 3 C 2 How can i write a Insert sql script for this table, eg: i should insert Rec_ID 3 while inserting Record for Dist_ID 1 and also Rec_ID 4 for Dist_ID 2, Suppose if many users inserting from different places, how to handle this situation. what is the best method? I have following 2 ideas, which is right idea or is there any other method to implement this 1) Select Max(Rec_ID) for the district, suppose if 2 people inserting at the same time will be a issue. 2) Put a Lock in the Stored Procedure

    G L P 3 Replies Last reply
    0
    • R Robymon

      Rec_ID Rec_Name Dist_ID 1 A 1 2 B 1 1 AA 2 2 AB 2 3 C 2 How can i write a Insert sql script for this table, eg: i should insert Rec_ID 3 while inserting Record for Dist_ID 1 and also Rec_ID 4 for Dist_ID 2, Suppose if many users inserting from different places, how to handle this situation. what is the best method? I have following 2 ideas, which is right idea or is there any other method to implement this 1) Select Max(Rec_ID) for the district, suppose if 2 people inserting at the same time will be a issue. 2) Put a Lock in the Stored Procedure

      G Offline
      G Offline
      GuyThiebaut
      wrote on last edited by
      #2

      Specifying Rec_ID as an identity[^] column may do all of that work for you.

      “That which can be asserted without evidence, can be dismissed without evidence.”

      ― Christopher Hitchens

      R 1 Reply Last reply
      0
      • G GuyThiebaut

        Specifying Rec_ID as an identity[^] column may do all of that work for you.

        “That which can be asserted without evidence, can be dismissed without evidence.”

        ― Christopher Hitchens

        R Offline
        R Offline
        Robymon
        wrote on last edited by
        #3

        I Cannot set it as Identity column, because based on the District ID should get the Next Rec_ID

        G Z 2 Replies Last reply
        0
        • R Robymon

          I Cannot set it as Identity column, because based on the District ID should get the Next Rec_ID

          G Offline
          G Offline
          GuyThiebaut
          wrote on last edited by
          #4

          In which case I do not understand what you are trying to do. Can you specify exactly what you need with a before and after example - thanks.

          “That which can be asserted without evidence, can be dismissed without evidence.”

          ― Christopher Hitchens

          1 Reply Last reply
          0
          • R Robymon

            Rec_ID Rec_Name Dist_ID 1 A 1 2 B 1 1 AA 2 2 AB 2 3 C 2 How can i write a Insert sql script for this table, eg: i should insert Rec_ID 3 while inserting Record for Dist_ID 1 and also Rec_ID 4 for Dist_ID 2, Suppose if many users inserting from different places, how to handle this situation. what is the best method? I have following 2 ideas, which is right idea or is there any other method to implement this 1) Select Max(Rec_ID) for the district, suppose if 2 people inserting at the same time will be a issue. 2) Put a Lock in the Stored Procedure

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

            Wrong order. Insert the records in the dependent tables first, and get their identity. Then insert the REC using the identities you fetched. Inserting data in multiple tables, appearing as a single atomic operation would require a "transaction".

            Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

            1 Reply Last reply
            0
            • R Robymon

              I Cannot set it as Identity column, because based on the District ID should get the Next Rec_ID

              Z Offline
              Z Offline
              ZurdoDev
              wrote on last edited by
              #6

              I'm with Guy. This does not make any sense.

              There are only 10 types of people in the world, those who understand binary and those who don't.

              1 Reply Last reply
              0
              • R Robymon

                Rec_ID Rec_Name Dist_ID 1 A 1 2 B 1 1 AA 2 2 AB 2 3 C 2 How can i write a Insert sql script for this table, eg: i should insert Rec_ID 3 while inserting Record for Dist_ID 1 and also Rec_ID 4 for Dist_ID 2, Suppose if many users inserting from different places, how to handle this situation. what is the best method? I have following 2 ideas, which is right idea or is there any other method to implement this 1) Select Max(Rec_ID) for the district, suppose if 2 people inserting at the same time will be a issue. 2) Put a Lock in the Stored Procedure

                P Offline
                P Offline
                PIEBALDconsult
                wrote on last edited by
                #7

                And if the workload isn't too heavy you could use a Web Service (WCF or similar) to provide a single access point so the clients don't actually touch the database. The service could then perform the actions one-by-one.

                You'll never get very far if all you do is follow instructions.

                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