should the "id" column always be auto_increment?

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
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

should the "id" column always be auto_increment?

Post by a94060 »

people usually leav ehte colum id auto incrementing, is this a smart idea? This also causes it to become the index rite?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I don't think autoincrementing creates an index automatically. Typically developers set the id field to autoincrement, primary key which does make the id an index.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

last I checked, auto-increment can only be set to work on primary keys. If you don't have one, you can't auto-increment.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

You can also use "sequences" which is how most other databases do it. I think most of the major PHP database classes for MySQL provide a sequence abstraction.
(#10850)
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

rite now i got the auto increment on the id and primary key on something else i think.
Post Reply