Solved

how can i reset my id numbers in mySQL so it starts to count from 1

Posted on 2008-10-23
5
314 Views
Last Modified: 2013-12-07
because i deleted some data in between because they were duplicate,  the id numbers are not exactly what i want which are is a 100 it is now a 1035 i tried this but didnt work ...help

ALTER TABLE property.property p set id AUTO_INCREMENT=1;
0
Comment
Question by:Lucinda08
  • 3
  • 2
5 Comments
 
LVL 26

Expert Comment

by:ushastry
ID: 22789149
Try this...(backup before running below code incase restore)

Pls change these... ID - > your auto-increment column name
                               tableName -> change with actual table name


SET @var_name = 0;
UPDATE tableName SET ID = (@var_name := @var_name +1);
ALTER TABLE tablename AUTO_INCREMENT = 1;
0
 

Author Comment

by:Lucinda08
ID: 22789197
thanks but  what is var_name
0
 
LVL 26

Expert Comment

by:ushastry
ID: 22789231
Its a variable...
0
 

Author Comment

by:Lucinda08
ID: 22789269
sorry i'm a beginner to this do you mean i should give var_name any name i want
0
 
LVL 26

Accepted Solution

by:
ushastry earned 500 total points
ID: 22793454
User variables are written as @var_name, where the variable name var_name may consist of alphanumeric characters from the current character set, ., _, and $

e.g Lucinda08 or ushastry
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
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

863 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

26 Experts available now in Live!

Get 1:1 Help Now