• kuldip.bhatt (1/20/2009)


    my questiion is

    Suppose there is one table and it has one primary key it's type is Integer.

    currrenlty this table has 20 rows but it's last indentity value is 60.

    then i use this dbcc command or not use it will be insert the next row

    at 61 am right or wrong ?

    then what is the use of this DBCC COmmand that i my Question ?

    Yes it'll get the value 61 (if the increment is set to 1).

    You can use dbcc to find the current identity value and current column value and reseed the current identity value to a new value of your choice or need.

    In your case, assuming the identity column has gaps (say 20,21,22,23) and you fire DBCC checkident('mytable', reseed, 20), the next time you try to insert any row in the table, it'll start with 21

    Pls go through the following test...

    create table #t

    (

    col1 bigint identity(1,1),

    col2 varchar(10)

    )

    -- run the below query 6 times

    insert into #t(col2)

    select 'a'

    union all

    select 'a'

    union all

    select 'a'

    union all

    select 'a'

    delete from #t where col1 between 20 and 25

    dbcc checkident("#t")

    --output

    Checking identity information: current identity value '29', current column value '29'.

    DBCC execution completed. If DBCC printed error messages, contact your system administrator.

    -- now reseeding the identity column

    dbcc checkident("#t",reseed,20)

    --output

    Checking identity information: current identity value '29', current column value '20'.

    DBCC execution completed. If DBCC printed error messages, contact your system administrator.

    -- again start inserting into the table

    it'll start from 21..... and will create duplicates if there are existing values.

    Hope this clarifies...



    Pradeep Singh