3 ms·
The article linked here makes a bad case against auto incrementing. In fact, I'm the opposite. Every field should have an ID that has nothing to do with the d
by jasonlotito 16y ago
The article linked here makes a bad case against auto incrementing. In fact, I'm the opposite. Every field should have an ID that has nothing to do with the data being stored. That, the record should not contain the (in the case of MySQL) primary key.
Take the traditional users table.
username
password
email
You might suggest that username can be the key. And sure, it will be a unique key. But, internally, I don't want to operate on the username. I'd rather operate on an internal value that is not related to the rest of the record. So I add an ID.
This ID doesn't have to be exposed to the user. However, should it ever pass that I need to let users change their username, I can easily by editing a single entries field.
Basically, your application logic shouldn't impact your business logic. Referencing record 12345 should also reference the same record, regardless of what else is changed.
- thibaut_barrere 16y agoI believe the OP was suggesting using a non-business key that isn't an incremented integer - typically some kind of guid. This allows to shard the data across multiples machines more efficiently, too. MongoDB (amongst others) use this by default.
- jasonlotito 16y agoMaybe. If he was, it wasn't clear, especially with "Your tables almost always have a better unique key." I took that as meaning using some element of the record. Regardless, you make a good point. =)