Am using the following notation to add a primary key to a table:
ALTER TABLE tablename
ADD id
INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST
And this works fine, but it seems to default the order of the table to the original input order of the rows, before adding this primary key. And this is not ideal for the current situation.
The order of this table is important, as it represents a menu structure, and I need the table to be ordered by parentId, as follows, before the primary key is added to the table:
+------+----------+---------------------------
| id | parentId | ...
+------+----------+---------------------------
| 1 | 1 | ...
+------+----------+---------------------------
| 2 | 1 | ...
+------+----------+---------------------------
| 3 | 2 | ...
+------+----------+---------------------------
| 4 | 2 | ...
+------+----------+---------------------------
| 5 | 2 | ...
+------+----------+---------------------------
.
.
.
This is how the table should look after the adding of the primary key column "id", but currently I can not seem to order the table by parentId before the id column is added.
I have been trying variations of the above query such as:
ALTER TABLE tablename
ADD id
INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST ORDER BY parentId ASC
but with no success.
Any suggestions??