identity column

  • Hi,

    Is it possible to set an autoincrement identity column a range value says from (1-999)?

  • yes - you can create the column as IDENTITY(int, 1,1)...but what do you want to do when you reach 999 ?!?!







    **ASCII stupid question, get a stupid ANSI !!!**

  • set the identity as (1,1) as usual. Then add a check constraint (Id >=1 and Id <=999)

  • an identity column is used to get a unique value for the row; in your case, you are looking for something that does not uniquely identify the row/field.

    i think it would be eser in your case to leave an indentity in place, and then select the modulus for the row  to group it into your 1000 increments:

    select uniqueID,(uniqueID % 1000) as uniqueID,somecolumn as description from sometable

     

    999  999 someval999

    1000    0 someval1000

    1001    1 someval1001

     

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • I think he needs to keep the table under 1000 rows. I already used that technic before and it works well. An instead of insert trigger can also do the same job (assuming he needs to do the same thing as me).

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

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