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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting fields from a table 1

Status
Not open for further replies.

woodyinoz

IS-IT--Management
Jan 8, 2002
215
GB
Hi all,

I am looking for a way of deleting a field from a table using code. I am not talking about a tableframe, I want to actually delete the field from an actual table.

Obviously I could query the table using the field out but I don't want to do this and am searching for a way of just deleting the field.

Can anyone suggest a way of doing this?

Thanks in advance,

Woody.
 
Woody,

Seems too obvious but restructuring the table springs to mind. I also looked under objectpal help and it gave the following code example:

The following example displays the Restructure Table dialog box and specifies Customer as the table to restructure. To complete the example, modify the structure and close the dialog box.

; showRestructureDlg::pushButton
method pushButton(var eventInfo Event)
; invoke the Restructure Table dialog box for Customer table
dlgRestructure("customer.db")
endMethod

Hopr this helps,

Lewy
 
Woody,

While Lewy's approach works for many situations, it could be frustrating to manually delete a table from multiple tables.

If you're trying to delete the same field from several tables, you may have better luck with the following process:

-- Use FileSystem to generate a list of tables in the directory (see for an example and possible starting place).

-- For each table you wish to modify:

1. Obtain a list of its fields (enumFieldStruct to a temp table in :pRIV:).

2. Open a Tcursor on the temp table containing the field definitions.

3. Locate and then delete the record for the field you want to remove.

4. Close the TCursor pointing to the temporary table.

5. Create a new table using the updated temporary table.

6. Use Add (or an insert query) to move data from the old table to the new one.

7. Use createIndex to create the necessary indexes.

Repeat as needed.

-- And, as always, make a complete backup before doing anything, just in case a serious accident occurs.

Hope this helps...

-- Lance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top