Alternative method to identity

  • Hi Folks ! I have varchar fields instead of identity ones, in order to assign a unique identifier to each row (justifying with left ceros). My java aplication generates the next value by executing a

    Select Max(<fieldname&gt  from <Table>

    But the problem is that this method is too slow in large inserts...We got this method because of operational requirements.

    The question: is there any faster method of "simulating" an identity value ???

    Thanks for your time !!!

     

  • store the max value into a table (only one row).

  • I agree with wz700.  I have done this in the past.  You will need to use WITH UPDLOCK (see BOL) though to ensure that the row is being updated properly and that the numbers remain in sync.

     



    Good Hunting!

    AJ Ahrens


    webmaster@kritter.net

  • Alternative approach is to have an Identity column, just for generating the identity number.

    Then have a computed column:

    (substring('0000000000',1,(10 - len([identity_col]))) + ltrim([identity_col])).

    The computed column would hold the "formatted" identity nymber.

    You can have a Unique index on the computed column.

    /rockmoose


    You must unlearn what You have learnt

  • Hi, Since your coloumn is of data type varchar you don't ave a problem. SQL server has a function NewGUID() that generates a new and unique New Gloabally Unique Identifier for a newly entered record so why don't u try that.

    Good luck!

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

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