Does the primary key have to be the first field in a database table?
Will the queries be slower if I put the id after the name?
CREATE TABLE users
(
name TEXT NOT NULL,
id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
site INTEGER NOT NULL,
...
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
I think that will complete the previous answers :
“There can be only one AUTO_INCREMENT column per table, it must be indexed, and it cannot have a DEFAULT value. An AUTO_INCREMENT column works properly only if it contains only positive values. Inserting a negative number is regarded as inserting a very large positive number. This is done to avoid precision problems when numbers “wrap” over from positive to negative and also to ensure that you do not accidentally get an AUTO_INCREMENT column that contains 0.”
So there is no limitation regarding the position of the primary key inside a table.
Hope this help.