-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Reset Auto Increment in MySql
PostPosted: Wed May 20, 2009 3:07 am 
Newbie

Joined: Wed May 20, 2009 3:00 am
Posts: 5
Hello, I have a requirement to reset the auto-increment id field of a table in my database on a certain condition. Right now I am doing it using SQLQuery. Is there a way to do this with HSQL. I want to avoid using SQL because I have already run into SQL issues while migrating from HSQLDB to MySql.


Top
 Profile  
 
 Post subject: Re: Reset Auto Increment in MySql
PostPosted: Wed May 20, 2009 7:43 am 
Regular
Regular

Joined: Wed Jun 20, 2007 1:53 am
Posts: 75
post your SQL query which resets MySql auto increment id


Top
 Profile  
 
 Post subject: Re: Reset Auto Increment in MySql
PostPosted: Fri May 22, 2009 1:13 am 
Newbie

Joined: Wed May 20, 2009 3:00 am
Posts: 5
The Following is the query :

ALTER TABLE USER_GROUP_ASSOCIATION AUTO_INCREMENT = 1


Top
 Profile  
 
 Post subject: Re: Reset Auto Increment in MySql
PostPosted: Tue May 26, 2009 10:48 am 
Regular
Regular

Joined: Wed Jun 20, 2007 1:53 am
Posts: 75
Hi,
Most probably auto_increment is used as a primary key, if so, its dangerous to reset it and it may cause primary key contraint error. So I want to know at what situation you would like to reset the auto_increment?


Top
 Profile  
 
 Post subject: Re: Reset Auto Increment in MySql
PostPosted: Tue May 26, 2009 2:01 pm 
Newbie

Joined: Wed May 20, 2009 3:00 am
Posts: 5
This particular table is re-initialized periodically from an external data source. This table actually maintains a many to many relationship between 2 other tables namely users and groups. The number of records inserted every time could be well over 10K, so if the population happens at a quick frequency, i will be at the risk of hitting the maximum.


Top
 Profile  
 
 Post subject: Re: Reset Auto Increment in MySql
PostPosted: Tue May 26, 2009 2:07 pm 
Newbie

Joined: Wed May 20, 2009 3:00 am
Posts: 5
Another option i thought of was to delete the table and recreate it at run time using hibernate. If that is easier i could use that option as well.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.