Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Renaming a table in a database
Message
From
01/06/1999 09:05:54
Kenneth Downs
Secure Data Software, Inc.
New York, United States
 
 
To
28/05/1999 17:28:30
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00224160
Message ID:
00224875
Views:
21
Bob,

>I'm trying to rename a table in a database. The RENAME TABLE command only modifies the alias in the database, but does not rename the file(s) on disk.
>
>The RENAME command does not work, and in fact creates an error.
>
>Does anyone know how to do this gracefully?
>

Gracefully? Probably not. But it is doable. The line of commands would be something like:

OPEN DATABASE MyDataBase
SET DATABASE TO MyDataBase
REMOVE TABLE MyTable
Rename MyTable.DBF TO MyNewName.DBF
Rename MyTable.CDX To MyNewName.CDX
Rename MyTable.FPT To MyNewName.FPT
ADD TABLE MyNewName

Of course you may now ask, "What happens to my captions, defaults, triggers, relations, etc?" They are lost.

You could try another approach here as well, something like this:
1. Open the database as a table
2. Find the record of ObjectType = "Table" with your table's name and note its ID number.
3. Select the records whose "ParentID" matches your table and put them off in a temporary table.
4. Close the DBC and rename the table as described above.
5. After adding the table back in, open the DBC as a table and find the record of OBjectType = "Table" with your table's new name. Note the new ID Number
6. Delete all records in the DBC with ParentID = the new ID Number
7. Append in the records from your temporary table, changing the ID Number at some point (preferably before you append).

You could still run into errors if you have relations, as they will name tables explicitly.

IMHO, the possibility for losing hours of painstakingly entered dictionary information is a staggering weakness of the DBC, which is otherwise very powerful and robust. There are a few choices here.

1. Many people swear by Stonefield Database Toolkit, which is supposed to take care of these things.
2. You can write your own set of Stonefield tools. I did it this way because I like to know how things work. I store everything in the DBC in a set of tables, and can completely rebuild the DBC from scratch at any time.

Hope this helps.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform