This is a discussion on create an auto_increment key in a table within the MySQL forums, part of the Database Server Software category; --> Hi all, I've to add an auto_increment field in a table with datas inside. The field will also become ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hi all, I've to add an auto_increment field in a table with datas inside. The field will also become the key of the table. The table has been used until now linked to a field and ordered by a date field. The new auto_increment value for every field must keep this order: 1- order by date field desc (the oldest first) 2- order by linkid asc How can I do this ? It is possible ? The SQL statement would greately be appreciated. Thanks for helping. Bob |
| |||
| On Aug 23, 9:04 am, "Bob Bedford" <b...@bedford.com> wrote: > Hi all, > > I've to add an auto_increment field in a table with datas inside. The field > will also become the key of the table. > > The table has been used until now linked to a field and ordered by a date > field. The new auto_increment value for every field must keep this order: > 1- order by date field desc (the oldest first) > 2- order by linkid asc > > How can I do this ? It is possible ? The SQL statement would greately be > appreciated. > > Thanks for helping. > > Bob Why does it matter? Tables don't have an order to them. You sort the results when you run a query -- not when you store the data. |
| ||||
| >I've to add an auto_increment field in a table with datas inside. The field >will also become the key of the table. alter table foo add id int not null auto_increment primary key; (If you've already got a primary key, you'll need to drop that index first). >The table has been used until now linked to a field and ordered by a date >field. The new auto_increment value for every field must keep this order: >1- order by date field desc (the oldest first) >2- order by linkid asc Tables do not have order. The results of queries have order when you use ORDER BY, otherwise you can't complain about the order. >How can I do this ? It is possible ? The SQL statement would greately be >appreciated. |