Unix Technical Forum

create an auto_increment key in a table

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 ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 11:27 AM
Bob Bedford
 
Posts: n/a
Default create an auto_increment key in a table

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


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 11:27 AM
ZeldorBlat
 
Posts: n/a
Default Re: create an auto_increment key in a table

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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 11:27 AM
Captain Paralytic
 
Posts: n/a
Default Re: create an auto_increment key in a table

On 23 Aug, 14:30, ZeldorBlat <zeldorb...@gmail.com> wrote:
| You sort the
| results when you run a query

Or you read them using an index.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 11:27 AM
Gordon Burditt
 
Posts: n/a
Default Re: create an auto_increment key in a table

>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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:17 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com