Solved

reset identity column to 0

Posted on 2014-01-12
8
297 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 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 500 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
Backup Solution for AWS

Read about how CloudBerry Backup fully integrates your backups with Amazon S3 and Amazon Glacier to provide military-grade encryption and dramatically cut storage costs on any platform.

 
LVL 83

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 10

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

730 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