Solved

Fix Identity column in a table

Posted on 1998-07-15
3
320 Views
Last Modified: 2006-11-17
I have a database with a table that has an Identity column.  It has worked fine for months.  All of a sudden I get duplicate row errors during inserts (complaining that the Identity column is being duplicated).  I ran a dbcc CHECKIDENT command and it returned: "current identity value '1', current column value '74155'."  I tried dbcc CHECKDB (and even updated statistics) and it didn't fix.  Does anybody know how I might resync the Identity column?
Thank You
0
Comment
Question by:dsegal
3 Comments
 
LVL 7

Expert Comment

by:spiridonov
ID: 1091781
I would suggest the wollowing sequence:
Rename the table
Recreate the table with origincal name
set 'identity_insert on' option
Insert data from the first table into new one using  option
set 'identity_insert off' option
recreate triggers on a new table
drop old table

0
 

Author Comment

by:dsegal
ID: 1091782
I could always drop and recreate the table, there must be some other explanation / fix!
0
 
LVL 2

Accepted Solution

by:
odessa earned 100 total points
ID: 1091783
Only fix I use and think is more efficient is to
remove Unicue Indexes (or Primary) on Id col
do inserts to point where you have dupplicates
to delete newly inserted records and
to recreate Indexes
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
TSQL Challenge... 7 37
Remove last comma in SQL Server column with Type Of nvarchar(Max) 3 28
TSQL convert date to string 4 37
Need return values from a stored procedure 8 21
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question