Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to add a column at a particular position?
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Database:
Visual FoxPro
Divers
Thread ID:
01018285
Message ID:
01018294
Vues:
18
>I can use "alter table add column" to add a new column at the end of the table column definition. Is there a way to add the new column at a particular position, such as before or after a certain existing column?
>
>Thanks!

With ALTER TABLE. No way :o(
USE YourTable
nNumFields = AFIELDS(aFlds)
DIMENSTION nNewArray[nNumFields+1,18]
*** Let's say you want to put your new field in 3th position
*** AFIELDS gives array with 18 elemets

ACOPY(aFlds,nNewArray,1,18*2,1)  && 18*2 - first two field definitions of the original table

nNewArray[3, 1] = "MyNewField"  && See HELP
nNewArray[3, 2] = "C"
nNewArray[3, 4] = 10
nNewArray[3, 5] = 0
.....
nNewArray[3,18] = 0

ACOPY(aFlds,nNewArray,18*3,-1,18*4)
CREATE TABLE Temptable FROM ARRAY nNewArray
SELECT TempTable
APPEND FROM YourTable
*** DO ALL INDEX ON Here
CLOSE DATA ALL
ERASE YourTable.*
RENAME TempTable.DBF TO YourTable.DBF
RENAME TempTable.FPT TO YourTable.FPT && If you have a Memo/GENERAL/BLOB fields
RENAME TempTable.CDX TO YourTable.CDX
Never tested this. Be sure you have a good beackup before running this.
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform