Create a unique ID or number for each record?

  • How can I create a unique ID or number for each record that is saved using a Stored Procedure? I need this for editing purposes

     

    Many thanks in advance

  • Not sure where you are using this field...  If it is within the table itself, look up IDENTITY in BOL.  If it is part of the processing, you can either use this same structure in a #TempTable or @TableVariable, or do the painstaking process of incrementing each value...

    I wasn't born stupid - I had to study.

  • thanks for pointing me in the right direction

  • I'm not sure why you don't create an identity column, (type Int or BigInt), in the table that you're storing the records to. That way you don't need any code, Sql does it for you, all you need to do is insert the data.

     

  • it's for editing purposes, I'd be using update on the record and as I won't know which field I'd be updating it'll be difficult keeping track of which field I'd be working on, the id would be a great help, thanks Dan

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply