Discussion:
Alter Table - adding multiple column at same time
(too old to reply)
Philippe Harnois
22 years ago
Permalink
Hi,

I want add multiple column with the following code

This code is in a For ... Next Loop

lcCompteur = PADL(ALLTRIM(STR(lnCompteur,2)), 2, "0")
lcAnn_FiscPP = "Ann_FiscPP" + lcCompteur + " n(4) "
lcAnn_FiscPA = "Ann_FiscPA" + lcCompteur + " n(4) "
lcPeriode = "Periode" + lcCompteur + " n(2) "
lcTotAnnPA = "TotAnnPA" + lcCompteur + " n(6) "
lcTotAnnPP = "TotAnnPP" + lcCompteur + " n(6) "
lcTotCliPA = "TotCliPA" + lcCompteur + " n(6) "
lcTotCliPP = "TotCliPP" + lcCompteur + " n(6) "
lcTotPriPA = "TotPriPA" + lcCompteur + " n(12,2) "
lcTotPriPP = "TotPriPP" + lcCompteur + " n(12,2) "
ALTER TABLE curStatistique ;
ADD COLUMN &lcPeriode ;
ADD COLUMN &lcAnn_FiscPA ;
ADD COLUMN &lcAnn_FiscPP ;
ADD COLUMN &lcTotAnnPA ;
ADD COLUMN &lcTotAnnPP ;
ADD COLUMN &lcTotCliPA ;
ADD COLUMN &lcTotCliPP ;
ADD COLUMN &lcTotPriPA ;
ADD COLUMN &lcTotPriPP

But when I execute the program, it's telling me that I have duplicate field
or invalid name when I try to alter table. Can I add more that one column at
the same time?
--
Philippe Harnois
PS Excuse me for my poor english...
Richard Flouriot
22 years ago
Permalink
Hi Philippe
Are you using a cursor created using CREATE CURSOR ? ALTER TABLE may produce
inconsistent results in that case.
PS Excuse my poor english...too :o)
...
Richard Flouriot
22 years ago
Permalink
Philippe,
I'd try to fill an Array with the content to aletr, and check it in the
debugger
Richard
...
Eric den Doop
22 years ago
Permalink
Hello, Philippe!

You cannot add multiple columns in a single ALTER TABLE command. The correct
syntax is:
ALTER TABLE mytable ADD COLUMN first_column C(5)
ALTER TABLE mytable ADD COLUMN second_column C(5)
etc
--
Eric den Doop
www.foxite.com - The Home Of The Visual FoxPro Experts - Powered By VFP8
Philippe Harnois
22 years ago
Permalink
You can add multiple column at the same time
My error was that I have two fields too long (12 digits ). I delete 2 digits
and it works fine

Thank
Post by Eric den Doop
Hello, Philippe!
You cannot add multiple columns in a single ALTER TABLE command. The correct
ALTER TABLE mytable ADD COLUMN first_column C(5)
ALTER TABLE mytable ADD COLUMN second_column C(5)
etc
--
Eric den Doop
www.foxite.com - The Home Of The Visual FoxPro Experts - Powered By VFP8
Anders Altberg
22 years ago
Permalink
Hi Eric
Not only can you have have multiple ADDs. You can use a single command like
ALTER TABLE T1 ADD col7 i ADD col8 C(4) ALTER fname C(15) RENAME fname TO
firstname
Anders
Post by Eric den Doop
Hello, Philippe!
PH> You can add multiple column at the same time
Learned a new thing today! Thanks.
--
Eric den Doop
www.foxite.com - The Home Of The Visual FoxPro Experts - Powered By VFP8
Eric den Doop
22 years ago
Permalink
Hi Anders,

Thanks for the additional info.
--
Eric den Doop
www.foxite.com - The Home Of The Visual FoxPro Experts - Powered By VFP8
Continue reading on narkive:
Loading...