resetting IDs on IDENTITY columns

  • I have a table :

    drop table REPORTING_FILES

    Create table REPORTING_FILES

    (

    DRF_FILE_ID INTEGER IDENTITY (1,1) PRIMARY KEY,

    DRF_FILE_NAME VARCHAR(50),

    DRF_SUBJECT_LINE varchar(50)

    )

    With entries :

    1 abc abc subject

    2 xyz xyz subject

    3 mnq mnq subject

    4 yyz yyz subject

    When I delete DRF_FILE_ID=2 , I have entry like

    1 abc abc subject

    3 mnq mnq subject

    4 yyz yyz subject

    I would like to have it as :

    1 abc abc subject

    2 mnq mnq subject

    3 yyz yyz subject

    How can I achive this?

    I have to reset this as by drop down list in .NET applcation uses the Index to display and delete the file, since index 2 is deleted, and not rearranged, its creating a problem.

    Thanks.

  • It's not really simple to do that with an identity column. Do you need it to do that for display purposes or is there another reason? I ask because the data will still display in ascending order by id since by default the primary key is the clustered index (unless you use an order by clause). If that is the reason just don't display the identity field.

  • And from a referential integrity standpoint, if the identity field is used as a foreign key elsewhere, you're going to have to either issue updates to each of the references or orphan a whole lot of data, depending on your setup. Take Jack's advice and leave it alone.

    -- You can't be late until you show up.

  • Thanks. I will leave it alone.

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

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