Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

reset identity column to 0

Posted on 2014-01-12
8
Medium Priority
?
310 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 84

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 2000 total points
ID: 39774407
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
ID: 39774414
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
ID: 39774417
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
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 39774421
You're welcome, glad to help.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 39774918
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
ID: 39774920
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 11

Expert Comment

by:HuaMinChen
ID: 39775702
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
ID: 39784880
thank you
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
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.

688 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