• If I am not misreading the original request, I think you are trying to get multiple pseudo-identity columns in a single table.

    This is a somewhat squirrely approach but it'd probably work for you as long as possible holes in your sequences are not a problem.

    This code is based on a discussion some time back (it may have been here at SSC; does anyone still have the link?) about doing pretty much what you wanted-- except for the "multiple columns" requirement. Each column that needs its own pseudo identity value needs its own SneakyIdentity table... Ideally you'd lock it down and document the bejeebers out of it so nobody stumbles in and tries to figure out what an empty table is doing in the system. (and potentially mungs the identity value) Add appropriate error trapping. You may want to put the code shown in a USP.

    -- create the table to start

    -- create table SneakyIdentity(rowid bigint identity PRIMARY KEY)

    -- drop table SneakyIdentity

    -- insert bumps "next identity row" but the rollback prevents the row from getting saved

    begin transaction

    insert into SneakyIdentity DEFAULT VALUES

    rollback transaction

    -- IN USP, this would actually be an OUTPUT parm so wouldn't need to declare here...

    declare @uid bigint

    select @uid = Scope_Identity()

    select @uid Retval

    -- the table stays empty

    select * from SneakyIdentity


    Cursors are useful if you don't know SQL