to auto increment or not to

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

to auto increment or not to

Post by GeXus »

For the ID column of a table, is there any reason not to auto increment? I know for replication it could be a problem, having to disable it on the replicated servers... but other than that is there any other problem with auto incrementing ids?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It's largely dependant on how your system needs to work. Generally speaking, I use auto_increment on the primary ID column nearly always. Whether a table has such a column or not depends on the function of the table. Cross linking tables rarely, if ever, need such a column for instance. Ancillary user tables will often have the user_id as primary key, since it's foreign, it's not auto-incremented.
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post by GeXus »

Perfect.. thanks!
Post Reply