473,394 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Why AUTO_INCREMENT field keeps previous values

Mike Kypriotis
I have a table with 2 rows so AUTO_INCREMENT biggest value is 2, I delete those 2 rows (table is now empty) and I insert another two but instead of AUTO_INCREMENT having values of 1 and 2 (as I wanted) it has 3 and 4 (in the insert statement I do not want to mention AUTO_INCREMENT field at all) any ideas how to correct it?
Feb 21 '12 #1
2 2205
Rabbit
12,516 Expert Mod 8TB
It keeps it for referential integrity. If you use that auto-increment field as a foreign key in another table, you don't want it to reset every time. Otherwise you end up with really bad data.

You can reset the auto increment field with
Expand|Select|Wrap|Line Numbers
  1. ALTER TABLE tableName AUTO_INCREMENT = 1;
Feb 21 '12 #2
true, since I wanted every time I empty my table to reset my key (to prevent from getting really big values for nothing) instead of a DELETE I used TRUNCATE (which resets the auto-increment)
Feb 28 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Bill Clark | last post by:
I have about 20,000 records pulled from Excel that I need to update. What I need to do is run an update query that bascially says: If a field is null, update it with the previous record value of...
3
by: cmm | last post by:
I am trying to create a view in MSSQL that has a column which is an auto increment (or unique id) field but it doesn't work the way I want it. Does anybody have an idea how to do this? The example...
4
by: devi | last post by:
Hi, In oracle I have a LAG function using which I could get the previous value of a field. Do we have anything similar to that in SQL Server or access? Thanks Devi
2
by: MLH | last post by:
Fields in MyTable: PostID PostDate RollQtyXfer RollDenomination RollCount37 RollCount23
3
by: ElJefe | last post by:
I want to add the values of one field for two different values in another field and come up with a sum total of many entires. For example; One field contains a specific type of work ranging from...
2
by: millisami | last post by:
I have a table with a primary varchar key and some others columns. I want to add a new column at the begining of the table which is Numeric auto_increment. When I add this new column via phpMyAdmin,...
1
by: Mob | last post by:
what is the best way to identify the current and previous values for form controls like text and checkbox in postback. Can this be done through viewstate ...
1
by: dkhansoft | last post by:
hi, i have one feedback form, if user miss some fields and enter submit, then form has to display message and restore all previous values he entered i m able to display message bt not able...
15
by: Maarten | last post by:
I've found some answers to my problem on this forum, but not exactly the answer I was looking for. Sorry if I've missed something. This is my situation: I am trying to make an insertion into an...
1
by: saagardn | last post by:
I am using Access 2007 on an XP machine. Is it possible to update one field with multiple values using a single SQL statement? I have tired to do this with the query builder, but keep getting a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.