Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Altering a table structure to match a new DBF template.

Status
Not open for further replies.

AndrewMozley

Programmer
Oct 15, 2005
621
GB
An application has been issued to several customers, and the underlying structure of one table needs to be altered (by program), to match the new layout. The changes are mainly the addition of new fields and changing the length of some fields.

I can do this up to a point by opening the live data and the new template, examining the fields in both tables with the AFIELDS() function; then using the ALTER TABLE command to add the new fields into the live data.

This works, and the application runs, using the new fields. However the fields in the live data may not be in the same order as those in the template.

So : the (existing) live data has fields :
Account C(8), Addr1 C(30), Postcode C(8)

and the new template has fields :
Account C(8), Addr1 C(30), Addr2 C(30), Postcode C(8)

After updating the live data, it has fields :
Account C(8), Addr1 C(30), Postcode C(8), Addr2 C(30)

As mentioned, the live data has all the fields to make the updated application work, but it would be nice to have the layout identical to the new template, with the fields in the same order.

Thanks.
 
You should rethink your idea of having the fields in a specific order. At least that's my opinion. The big question is WHY you want this, I don't think you can come up with a good enough reason to justify the extra work.
 
Andrew,

The only way to do this programmatically would be to create entirely new tables containing the fields in the desired order; then append the data from the old tables; then delete the old tables; then rename the new tables to match the original names.

Whether this will be worth the trouble (including possibly a certain amount of inconvenience for the customer) is for you to decide.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top