Solved

reset identity column to 0

Posted on 2014-01-12
8
287 Views
Last Modified: 2014-01-16
Hi Experts
i am trying to reset the value of identity column to start again from 0 or 1
i am using

DBCC CHECKIDENT ('courses.tbl_courses', reseed, 0)

Open in new window


but its not working, still the first column coming 401

What is wrong with the statement? did i miss any thing?
0
Comment
Question by:AZZA-KHAMEES
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 82

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 500 total points
Comment Utility
If you have existing rows, an Identity column (or autoincrement in other servers) will find the highest existing number and add one to that.  No matter what you tell it to start at.  It will never really 'reset' to 0 because it will scan the column and find the current highest number and add 1 to it.
0
 

Accepted Solution

by:
AZZA-KHAMEES earned 0 total points
Comment Utility
thank you for the reply
i was able to do this by following the steps in this link

How to RESET identity columns in SQL Server

since i need a new data in the table, i had to remove the relations between the tables and delete the data
and it worked

thank you
0
 

Expert Comment

by:coderdn
Comment Utility
In case the column is just an identity column(and not primary key), the command
DBCC CHECKIDENT (....)

Open in new window

should reset the identity to 1. While if the column is primary key as well, then this command does not reset the identity, next identity would be generated according to existing maximum identity.
Seems like your case is the second one.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
You're welcome, glad to help.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
Dave,

If you have existing rows, an Identity column (or autoincrement in other servers) will find the highest existing number and add one to that.
You may want to double check that.  You can reset an IDENTITY column to any value using DBCC CHECKIDENT(), regardless of the existing rows.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
While if the column is primary key as well, then this command does not reset the identity, next identity would be generated according to existing maximum identity.
I am afraid that is not true.  The act of reseeding has no bearing on existing rows let alone a Primary Key.
0
 
LVL 10

Expert Comment

by:HuaMinChen
Comment Utility
One way to reset identity column, is to truncate the table, and it means you have to back up the whole table first.
0
 

Author Closing Comment

by:AZZA-KHAMEES
Comment Utility
thank you
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now