DBCC CHECKIDENT

  • Hi,

    I want to know, can we define reseed value at the time of creating table.

    Or can we define reseed value in the structure of table itself ?

    Suppose there is master table whose id is in transaction table.

    Now say a programmer delete some records through query analyzer or physically through enterprise manager , without using DBCC CHECKIDENT.

    If we repopulate the master table then new id will be generated and the transactiobn table will will have diffrent id with same value ?How to avoid such situation ?

    Is there any way out ?what is the ideal way ?

    [font="Verdana"]Regards
    Kumar Harsh[/font]

    :unsure:

  • Hi

    First the answer; yes you can specify the seed within the table creation:

    DECLARE @t TABLE (id INT IDENTITY(50, 1), txt VARCHAR(100))

    INSERT INTO @t

    SELECT 'hello'

    UNION SELECT 'world'

    SELECT * FROM @t

    Question:

    Why does it matter if your id has gaps? It is just a unique ID not a sequence. If you use it in referenced tables you should use non-identity INT columns and INSERT the created id from your master table.

    ... maybe I misunderstood your question.

    Greets

    Flo

  • One close to ideal solution is

    > use foriegn key constraint on the transaction table to avoid deletes on the master table.

    > In case if want to repopulate master table( after deleting transactiion table) then

    Use Identity_Insert on the master table.

  • Hi

    As suggested by nagar has Foreign Keys, but to provide good solution can you tell us your complete requirement.

    Thanks -- Vijaya Kadiyala

    http://www.dotnetvj.vom

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

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