Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old November 3rd, 2003, 11:03 AM
csuffel csuffel is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 2 csuffel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
mySQL: auto_increment

Hello,

i need a real unique counter for every entry in my mySQL database.
auto_increment works fine so far. The only problem is, that the counter is reset with every DELETE FROM 'tablename' statement.

Is there any way to suppress that behaviour?
How can i get a counter, that is NEVER reset?

Thanks,
Claus

Reply With Quote
  #2  
Old November 4th, 2003, 10:47 PM
sliver's Avatar
sliver sliver is offline
Moderator
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: WI, USA
Posts: 932 sliver User rank is Private First Class (20 - 50 Reputation Level)sliver User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 11 h
Reputation Power: 3
Send a message via AIM to sliver Send a message via XFire to sliver
RE: mySQL: auto_increment

I don't know what you mean by reset. It sounds like it should work. For example say you have:

1
2
3
4
5
In your table, if you delete 5 the next numbers is still 6, so.....

Reply With Quote
  #3  
Old November 5th, 2003, 11:32 PM
prycejones prycejones is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 87 prycejones User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 44 sec
Reputation Power: 3
Send a message via ICQ to prycejones
RE: mySQL: auto_increment

I agree with Silver.
As long as you dont touch it the auto_increment field will increment by 1 each record you add. You can get into trouble if you start messing with it but as long as you leave it well alone you will be ok. If you need to know what number will be allocated next you can do this by "SHOW TABLE STATUS" as an MYSQL query and you get a list of all tables in your db. There is one column in this display that will tell you the next auto_increment number.
As a side note of interest:
I use an auto_increment field in every table in a database I am designing at the moment. It is the first field and is always named xxRECID where xx is the table name idetifier (E.G. CM for Customer Master etc). This field is a mediumint unsigned and is auto_increment. I have these RECID fields alot in helping me to maintain the database and its structure. (They are not always utilized but always there just in case). For "master" files I use the RECID to identify that record (E.G. 00001 = John Smith High Street Anytown). For transitory/transaction type files I use the RECID field to help maintain the record (E.G. 001234 Invoice A123 GBP00123.45) etc etc.

As another idea you could use timestamp or datetime fields to help you identify your records but beware if you create and more than 1 record a second as the stamp ist yyyymmddhhmmss.

Hope this all helps - sorry I have gone on a bit

Pryce


Reply With Quote
  #4  
Old November 6th, 2003, 07:41 AM
csuffel csuffel is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 2 csuffel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: mySQL: auto_increment

Hello,

thanks for your postings.

It seems that i didn't describe my problem exact enough. The auto_increment works fine as long as i do not delete ALL the records of the table.
But when i enter the command

DELETE FROM 'tablename'

all records are deleted and the auto_increment counter is reset to 1.

Is there any way to prevent mySQL from resetting the counter in this case?

Claus

Reply With Quote
  #5  
Old November 6th, 2003, 11:48 AM
prycejones prycejones is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 87 prycejones User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 44 sec
Reputation Power: 3
Send a message via ICQ to prycejones
RE: mySQL: auto_increment

Hello Claus,

If you run "show table status" you can get the next auto_increment that will be used when the next record is added. Keep this number before you do a "delete all ...".
Then, when you add the first record after you have deleted all the records, use the kept "next_number" from the "show table status".
I have just tested this and it works.
If you want to have a look at an example of the results from a "show table status" look at this page on my site and scroll down to the "meta_tables_status_display FUNCTION".
http://www.prycejones.com/caravan/meta_functions_test.php

Hope this idea helps.

If all this is too complicated then another idea is to keep the "last record used" number in a small file/table somewhere, and just use this when ever you are writing a record.

Good luck

Pryce

mailto: pryce AT prycejones DOT com

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > mySQL: auto_increment


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek