Automatically Generated Numbers

  • I'm modifying a table that already has an identity column and a uniqueidentifier column. I would like to be able to generate a number for each record (that clients can use to refer to the record), and I don't want to give them either of the two previously mentioned values. Is there anything I can do? You can't have more than one identity column in table, right? If not, is there no way for me to have this number automatically generated by Sql Server? I know that I could create this in the application and save it to the db, but I was hoping to avoid that if possible. Thanks.

  • You could create a computed column and do something like identity + 1. Why can't they see the identity?

  • There isn't really a good reason to not show the client the identity, other than personal preference. A computed column should do well, though. Thanks.

  • How is the data entered into the database?

  • Heh... just reverse the IDENTITY number...

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • If you dont want to show Identity column in table, According to me you have two options:

    a) As mentioned in other's reply use computed column

    b) Create a table for each identity column, first insert value in that, then refer that value and use for your main table.

    Like in Oracle you dont have auto-number, but you have sequence. Sequence generate value for you, which can be used for your custom table.

    Hope it will help you

    🙂

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

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