RSS Forums RSS
Please support our MySQL advertiser: Programming Forums

generate unique primary key

Join Date: Jun 2005
Location: Kansas City, Missouri, USA
Posts: 345
Reputation: Troy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 4
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: generate unique primary key

  #7  
Jun 16th, 2005
All the answers posted are correct, but I think you are still better off to allow MySql's auto-number feature to manage your unique id key. Make sure you set the id field type to BIGINT.

Like I said before, gaps in the sequence do not matter. Auto-number's purpose is not to maintain a nice sequence of id's but rather to maintain a unique id.

As mentioned by another poster, you can always generate your own unique id within your code, and use that when inserting new records, but that increases the chance of hurting data integrity. Especially if you have a large application with multiple places in the code the table is inserted into. Database systems started implementing methods to manage unique ID's and relational integrity because it's too easy for us programmers to screw it up if we try to manage it in our code!
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 11:55 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC