|
Post by billw on Oct 17, 2007 7:04:27 GMT -5
To id, or not to id? That is the question.
While learning MySQL, I heard it was best practice to always have an INTEGER PRIMARY KEY field on all of my tables. What this is for, I do not recall. Anyway, is it best to keep those, or can I just switch to name-based keys?
|
|
|
Post by turbov21 on Oct 17, 2007 8:44:07 GMT -5
I use interegers and floats because I'm lazy and prefer incrementing numbers to creating unique strings. Mostly what you want is something that will make a record unique from all the others, for times when you do more complex, multi-table queries.
|
|
|
Post by colinmac on Oct 17, 2007 15:58:30 GMT -5
A key should be a value, or set of values, that is guaranteed to be unique for any row in a database table. Having an INTEGER PRIMARY KEY column is a convenient way of ensuring this.
SQLite automatically generates a column for each table, called rowid, which increments as rows are added to the table (at least until the table is full). Because of this, INTEGER PRIMARY KEY is largely redundant with SQLite, but it does no harm and might provide consistency of code for porting the SQL to other databases.
Colin
|
|