Mike Mapsnac wrote:

Thanks.

Just for curiosity. Why "truncate" was necessary in my case? I just create a table and try to insert some values.

Truncate is necessary because MySQL keeps track of autoincrement values for each table. Simply deleting a record ( or all records ) has no effect on the value of the next autoincrement field for a table.


If a have a table with 100 records, and I delete records number 72, for whatever reason, I don't want MySQL to use 72 as the next auto-increment value; I want it to use 101. If I was given 72, it could create all sorts of problems if there are references to records #72 in other tables. Which record would they refer to? The initial one, or the current one, of maybe another one that was deleted some time ago? It only makes sense to keep the autoincrement field constantly incrementing. If you delete a record, that auto-increment value should never come back.

So deleting all records will NOT reset the autoincrement value. Dropping the table will. I think there MAY be a command you can give MySQL to force it to start the auto-increment values at a particular point, but I've never been interested in doing that, so I don't know what it is.

--
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: [EMAIL PROTECTED]
website: http://www.nusconsulting.com.au


-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to