Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread Adding AutoInc Field using ALTER TABLE
Wed, Sep 18 2013 6:34 AMPermanent Link

Alex Vastich

Hi,

DBISAM V3.30

I run the following SQL statements

select gender, surname into memory test from staff order by gender, surname;
alter table memory test ADD functionUniqueCode AUTOINC;
select * from memory test;

Since it is being placed in a new table I would have expected that the autoinc field addition would have created incremental numbers from 1 to x for females and continuing on from x+1 to y for males.  However it appears to be instead assigning the numbers based on the physical original order of entry of the record.

Unfortunately this defeats the purpose of me doing this and that is to be able to number in sorted order from 1,2,3 etc.  Is there amother way to achieve this rather rudimentary task?

Thanks in advance for your help.
Al
Wed, Sep 18 2013 12:44 PMPermanent Link

Fernando Dias

Team Elevate Team Elevate

Alex

Is this DBISAM V3 or V4 ?

--
Fernando Dias
[Team Elevate]
Wed, Sep 18 2013 1:13 PMPermanent Link

Fernando Dias

Team Elevate Team Elevate

Alex,

Oh, stupid question, the first thing you said was it is V3  Smiley

Ok, so I'm not sure if it works because I dont have V3 installed any more so I can't test, but here it goes:

SELECT Gender, Surname INTO MEMORY Test FROM Staff TOP 0 ;

INSERT INTO MEMORY Test
  SELECT Gender, Surname FROM Staff ORDER BY Gender, Surname;

ALTER TABLE MEMORY Test ADD functionUniqueCode AUTOINC;

SELECT * FROM MEMORY Test;


Note:
I can't remember if TOP existed already in V3.30. If it doesn't work just replace it with any always false condition , like  "WHEN 1=0" or something like that.

--
Fernando Dias
[Team Elevate]
Wed, Sep 18 2013 7:54 PMPermanent Link

Alex Vastich

Hi Fernando,

That worked a treat, I really appreciate your help.

Regards
Alex
Image