Solved

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

Posted on 2008-10-23
5
316 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Create Index on a Materialized View 5 20
SQL Syntax 5 34
get column names from table in vb.net 8 27
What's wrong with this T-SQL Foreign Key? 7 42
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

776 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