Solved

reset identity column to 0

Posted on 2014-01-12
8
306 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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 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

CHALLENGE LAB: Troubleshooting Connectivity Issues

Goal: Fix the connectivity issue in the lab's AWS environment so that you can SSH into the provided EC2 instance.  

Question has a verified solution.

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

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
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
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.

630 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