Solved

Fix Identity column in a table

Posted on 1998-07-15
3
311 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
export sql results to csv 6 36
Webservices in T-SQL 3 31
Return 0 on SQL count 24 30
SQL Server Import/Error Wizard error 12 19
I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

810 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