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. Web Development
  3. ASP.NET
  4. problem with primary key

problem with primary key

Scheduled Pinned Locked Moved ASP.NET
databasehelpsql-serversysadminquestion
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.
  • S Offline
    S Offline
    shankbond
    wrote on last edited by
    #1

    Hi, I am developing a database(in SQL SERVER 2005) for a website, as you know that there can be a unknown amount of users surfing a website. I am putting some registration related values in a table and my table is having a unique primary key with IDENTITY(1,1). now the problem is I need that primary key value as soon as it is created in the table. so that I may use that value to add( insert) some other values in other tables. can it be done? I have thought of using timestamp values as they are always unique to every row. I have read somewhere that whenever a query is executed a value is returned such as 1 row affected or something like that, is it possible to return the timestamp value in place of the above message, I really have no idea. If it can then may be I can use some query like SELECT id FROM table WHERE timestamp=....; please reply YOUR help shall be appreciated thank YOU shankbond

    M L Z 3 Replies Last reply
    0
    • S shankbond

      Hi, I am developing a database(in SQL SERVER 2005) for a website, as you know that there can be a unknown amount of users surfing a website. I am putting some registration related values in a table and my table is having a unique primary key with IDENTITY(1,1). now the problem is I need that primary key value as soon as it is created in the table. so that I may use that value to add( insert) some other values in other tables. can it be done? I have thought of using timestamp values as they are always unique to every row. I have read somewhere that whenever a query is executed a value is returned such as 1 row affected or something like that, is it possible to return the timestamp value in place of the above message, I really have no idea. If it can then may be I can use some query like SELECT id FROM table WHERE timestamp=....; please reply YOUR help shall be appreciated thank YOU shankbond

      M Offline
      M Offline
      Manas Bhardwaj
      wrote on last edited by
      #2

      And what does it has to do with ASP.Net?

      Manas Bhardwaj Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

      1 Reply Last reply
      0
      • S shankbond

        Hi, I am developing a database(in SQL SERVER 2005) for a website, as you know that there can be a unknown amount of users surfing a website. I am putting some registration related values in a table and my table is having a unique primary key with IDENTITY(1,1). now the problem is I need that primary key value as soon as it is created in the table. so that I may use that value to add( insert) some other values in other tables. can it be done? I have thought of using timestamp values as they are always unique to every row. I have read somewhere that whenever a query is executed a value is returned such as 1 row affected or something like that, is it possible to return the timestamp value in place of the above message, I really have no idea. If it can then may be I can use some query like SELECT id FROM table WHERE timestamp=....; please reply YOUR help shall be appreciated thank YOU shankbond

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

        after the Insert query fire Select scope_identity() This will return the last inserted identity

        Regards Aman Bhullar www.arlivesupport.com[^]

        D 1 Reply Last reply
        0
        • L Lost User

          after the Insert query fire Select scope_identity() This will return the last inserted identity

          Regards Aman Bhullar www.arlivesupport.com[^]

          D Offline
          D Offline
          David Mujica
          wrote on last edited by
          #4

          check this explaination out. very nice. http://davidhayden.com/blog/dave/archive/2006/01/17/2736.aspx[^]

          1 Reply Last reply
          0
          • S shankbond

            Hi, I am developing a database(in SQL SERVER 2005) for a website, as you know that there can be a unknown amount of users surfing a website. I am putting some registration related values in a table and my table is having a unique primary key with IDENTITY(1,1). now the problem is I need that primary key value as soon as it is created in the table. so that I may use that value to add( insert) some other values in other tables. can it be done? I have thought of using timestamp values as they are always unique to every row. I have read somewhere that whenever a query is executed a value is returned such as 1 row affected or something like that, is it possible to return the timestamp value in place of the above message, I really have no idea. If it can then may be I can use some query like SELECT id FROM table WHERE timestamp=....; please reply YOUR help shall be appreciated thank YOU shankbond

            Z Offline
            Z Offline
            Zoki Manas
            wrote on last edited by
            #5

            If you are executing your INSERT command in a stored procedure, you can assign ID value of the inserted data to a local variable. Example: declare @returnID -- here goes your insert statement set @return = @@identity With this you have the value of the ID in the local variable, that you can return o your code as return parameter from the stored procedure.

            S L 2 Replies Last reply
            0
            • Z Zoki Manas

              If you are executing your INSERT command in a stored procedure, you can assign ID value of the inserted data to a local variable. Example: declare @returnID -- here goes your insert statement set @return = @@identity With this you have the value of the ID in the local variable, that you can return o your code as return parameter from the stored procedure.

              S Offline
              S Offline
              shankbond
              wrote on last edited by
              #6

              I mistakenly posted this thread in asp.net

              1 Reply Last reply
              0
              • Z Zoki Manas

                If you are executing your INSERT command in a stored procedure, you can assign ID value of the inserted data to a local variable. Example: declare @returnID -- here goes your insert statement set @return = @@identity With this you have the value of the ID in the local variable, that you can return o your code as return parameter from the stored procedure.

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

                Please read the article http://davidhayden.com/blog/dave/archive/2006/01/17/2736.aspx[^]

                Regards Aman Bhullar www.arlivesupport.com[^]

                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