PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.databases.mysql > Add an Auto_increment field problem
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Add an Auto_increment field problem

Réponse
 
LinkBack Outils de la discussion
Vieux 11/02/2008, 17h09   #1
Bob Bedford
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Add an Auto_increment field problem

Hi all,

I'm trying to add an auto_increment field on a table that doesn't have
primary key.

What I'd like is to have the auto_increment order based on a date field for
every record.

To do so, I've:

1 - changed the position of this field to the first position
2 - added the auto_increment field and set it as primary key
3 - changed the position of the date field back.

I Tought the order of the records was taken based on the field value that's
why I placed on the first place but it didn't change anything.

I tried to create a little program in Delphi but with no success as even
trying to set manually the value, when setting the auto_increment field then
the values are re-affected.

How can I do that ? I absolutely need to sort the values based on the date
for setting the auto_Increment value.

Bob


  Réponse avec citation
Vieux 11/02/2008, 17h27   #2
Luuk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Add an Auto_increment field problem

Bob Bedford schreef:
> Hi all,
>
> I'm trying to add an auto_increment field on a table that doesn't have
> primary key.
>
> What I'd like is to have the auto_increment order based on a date field for
> every record.
>
> To do so, I've:
>
> 1 - changed the position of this field to the first position
> 2 - added the auto_increment field and set it as primary key
> 3 - changed the position of the date field back.
>
> I Tought the order of the records was taken based on the field value that's
> why I placed on the first place but it didn't change anything.
>
> I tried to create a little program in Delphi but with no success as even
> trying to set manually the value, when setting the auto_increment field then
> the values are re-affected.
>
> How can I do that ? I absolutely need to sort the values based on the date
> for setting the auto_Increment value.
>
> Bob
>
>


set @id:=0;
select @id:=@id+1 as id, yourdate from yourfile
order by yourdate;

if you get it, you can change the select to an UPDATE.

--
Luuk
  Réponse avec citation
Vieux 11/02/2008, 21h48   #3
Bob Bedford
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Add an Auto_increment field problem

> set @id:=0;
> select @id:=@id+1 as id, yourdate from yourfile
> order by yourdate;
>
> if you get it, you can change the select to an UPDATE.


Hi Luuk,

Thanks for your . The select works fine, thanks. Unfortunately I'm not
enough "MYSQL aware" to know how to change to an update.
Could you please me a little more ?

Thanks for ing.

Bob


  Réponse avec citation
Vieux 11/02/2008, 22h02   #4
Luuk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Add an Auto_increment field problem

Bob Bedford schreef:
>> set @id:=0;
>> select @id:=@id+1 as id, yourdate from yourfile
>> order by yourdate;
>>
>> if you get it, you can change the select to an UPDATE.

>
> Hi Luuk,
>
> Thanks for your . The select works fine, thanks. Unfortunately I'm not
> enough "MYSQL aware" to know how to change to an update.
> Could you please me a little more ?
>
> Thanks for ing.
>
> Bob
>
>


set @id:=0;
UNDATE yourfile set id=@id:=@id+1 ORDER BY yourdate

--
Luuk
  Réponse avec citation
Vieux 11/02/2008, 22h10   #5
Bob Bedford
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Add an Auto_increment field problem

> set @id:=0;
> UNDATE yourfile set id=@id:=@id+1 ORDER BY yourdate


You are a king Luuk !!!!

I spent 3 hours without being able to do it and you did it in 2 lines of
Mysql !!!!

Thanks a lot !!!!!!


  Réponse avec citation
Vieux 11/02/2008, 22h15   #6
Luuk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Add an Auto_increment field problem

Bob Bedford schreef:
>> set @id:=0;
>> UNDATE yourfile set id=@id:=@id+1 ORDER BY yourdate

>
> You are a king Luuk !!!!
>
> I spent 3 hours without being able to do it and you did it in 2 lines of
> Mysql !!!!
>
> Thanks a lot !!!!!!
>
>


somone in this group provided the example some days, (or weeks?) ago ;-)


--
Luuk
  Réponse avec citation
Vieux 11/02/2008, 22h20   #7
Rik Wasmus
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Add an Auto_increment field problem

On Mon, 11 Feb 2008 23:15:10 +0100, Luuk <Luuk@invalid.lan> wrote:

> Bob Bedford schreef:
>>> set @id:=0;
>>> UNDATE yourfile set id=@id:=@id+1 ORDER BY yourdate

>> You are a king Luuk !!!!
>> I spent 3 hours without being able to do it and you did it in 2 lines
>> of Mysql !!!!
>> Thanks a lot !!!!!!

>
> somone in this group provided the example some days, (or weeks?) ago ;-)


You're welcome :P
--
Rik Wasmus
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 18h57.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12630 seconds with 15 queries