using autoincrement id

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
meee
Forum Newbie
Posts: 18
Joined: Wed Feb 04, 2009 1:38 pm

using autoincrement id

Post by meee »

I am wondering if it is recommended to use autoincrement fileds even if I don't need it?

As for example I have tables users, companies and employees. Inside table employees are user that joined a company.

The structure of table employees is as the following:
fieldId | companyId | userId | levelAccess

In this case filedId is just autoincrement without any value, it is just for the my record and it could be just without.

So should I remove fieldId from the table?

This was just one example of table where I don't need autoincrement id. I hear one time from somebody that he use autoincrement id in all tables. That is why I put it, but I am not sure if this has any sense.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: using autoincrement id

Post by John Cartwright »

- If you never need a unique id for the record, then don't use it.
- If you may need to join the data from another table, it is always far faster to use an auto-inc primary key to perform the join.
- If you need to look up individual records, then use it.
Post Reply