MySql auto increment

hello experts,

I have a created a table with primary key as auto increment and i am accessing that table from my application using Hibernate.

For example,i have inserted 10 records from 1 to 10 as primary key(auto incremented)....if i delete any record from my application and inserts new record it is entering as 11 th record........how to make the table such that it should not break the sequence.

If i delete 5th record, the next record(6th) should occupy that place.....is it possible..!!

Thanks..!!
perfectobjectAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Om PrakashCommented:
Then instead of making the column as auto incerment, you can manually insert data.

Find the max + 1 value from this table and use this value to insert in new record.
0
theGhost_k8Database ConsultantCommented:
Delete doesn't cause auto increment value to reset. This happens only when you truncate.
If you want to manually change auto increment value, you may :
ALTER TABLE tblname AUTO_INCREMENT = <NUMBER>;

And this too you may do for last columns, Mysql will not let you "fill the gaps"...
In case if you have records 1..10 and you delete record #5. and do:
ALTER TABLE tblname AUTO_INCREMENT = 5;
You will get error when you'll insert for next record as auto increment will start counting from 5... So 6 will be present in your table..

http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
theGhost_k8Database ConsultantCommented:
@om_prakash_p: This will still not satisfy the need.
You cannot fill the gap :) if deleted 5th, you cannot generate that.
It seems this is not possible.
0
nasirbestCommented:
yes, it is not possible, but with complex and useless programming.

however if you so concious about sequence why you delete records from table? only a update can do the job

*. add one more column in db 'enabled'
*. update / set 'enabled' to false/true as per your needs.
*. in where clause of select statements check only 'enabled'
0
perfectobjectAuthor Commented:
Thanks..!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.