specifying an identity increment other than n+1?

  • Is there a way to specify an identity increment value other than n+1? Say, logarithmic?

    Also, related, is there a way to do something like this:

    DECLARE @example TABLE ([id] INT IDENTITY(0,1),

    [num] AS (SELECT COUNT(*) FROM @example)

    )

    or do I have to use a trigger?

  • Can you describe what you think your DECLARE is doing?

    You can use increments other than +1 or -1, but I believe they need to be integer. You can check BOL for certainty - rather than take my word for it.

    Incidentally, I read your DECLARE as recursive.

  • Yes, it is sort of recursive. In the example, every new row will have the number of rows currently in the database (might go up, might go down). Trouble is, SQL complains that subqueries are not allowed (phooey on them).

  • you can specify an Identity column and the a calculated column that uses that Identity value to execute a function that will return your logarithmic value.

    Cheers,


    * Noel

  • You're right; I found how to do that. However, is there any way to do the thing in my example -- introspectively get data from the table at the time of insert as part of the insert (or does it have to be done with a trigger)?

  • You can do it in a user defined function, not necessarily a trigger.


    * Noel

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

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