how to alter the primarykey column

  • hi

    this is mytable design..

    CREATE TABLE [dbo].[NewPriority](

    [PriorityID] [int] IDENTITY(1,1) NOT NULL,

    [Name] [nvarchar](50) NOT NULL,

    [ImageUrl] [nvarchar](50) NULL,

    CONSTRAINT [PK__Priority__07F6335A] PRIMARY KEY CLUSTERED

    (

    [PriorityID] ASC

    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

    ) ON [PRIMARY]

    I have created table and stored some data.The id incrimented ..1,2,3..

    after I have deleted all the data.

    Now I insert any record it will be start at where the id as previous generated. I want to incriment start from 1..

    how can i alter my table without delete table.

    Regards:

    Giri.D

    Thanks
    Dastagiri.D

  • From BOL (Books Online):

    DBCC CHECKIDENT

    (

    table_name

    [ , { NORESEED | { RESEED [ , new_reseed_value ] } } ]

    )

    [ WITH NO_INFOMSGS ]

    You want to use the RESEED option.

  • As Lynn Petis said, very simple:

    DBCC CHECKIDENT (YOUR_TABLE_NAME, RESEED, 0)!

    Or if you plan to delete all data in your table, you just Truncate the table and the Identity value will come back to the null value and sure that it will start from 1!

    :w00t:

    ============================================================
    SELECT YOUR PROBLEM FROM SSC.com WHERE PROBLEM DESCRIPTION =
    http://www.sqlservercentral.com/articles/Best+Practices/61537/[/url]

Viewing 3 posts - 1 through 2 (of 2 total)

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