Identity Seed

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • William Ortenberg

    Identity Seed

    Can I change the value of a column's identity seed programmaticall y? If
    so, how?

    Thanks in advance.

  • Simon Hayes

    #2
    Re: Identity Seed

    William Ortenberg <billort@pacbel l.net> wrote in message news:<v%FYa.272 4$yF6.589@newss vr22.news.prodi gy.com>...[color=blue]
    > Can I change the value of a column's identity seed programmaticall y? If
    > so, how?
    >
    > Thanks in advance.[/color]

    You can use DBCC CHECKIDENT with RESEED, but the new value is not
    permanent. If you truncate the table, the seed will return to the
    original value specified when you created the table.

    If you want to change the seed value permanently, then you'll have to
    recreate the table with the new seed specified in the column
    definition.

    Simon

    create table dbo.t (
    col1 int identity(1,1)
    )

    insert into t default values
    select scope_identity( ) -- 1

    dbcc checkident(t, RESEED, 5)

    insert into t default values
    select scope_identity( ) -- 6

    truncate table dbo.t

    insert into t default values
    select scope_identity( ) -- 1

    drop table dbo.t

    Comment

    • Mystery Man

      #3
      Re: Identity Seed

      Hi William, The SET IDENTITY_INSERT command allows explicit values to
      be inserted into the identity column of a table.

      There are examples in the online help.

      I have used this many times for migration of legacy data into SQL

      Comment

      Working...