Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.
RENAME TABLE
This command lets you change the long name of a table in a database.
<a name=Usage>RENAME TABLE OldName TO NewName</a>
Only the database itself is updated, not things based on the table, though. So you do have to modify your own code and forms, as well as any generated code, from tools like the RI Builder or GENDBC code. Even worse, any views that are based on a renamed table won't work anymore. You can't even open them up in the View Designer to fix the problem. The solution is to use DBSetProp() to gather and store all the relevant properties, and then redefine the view. The big problem is, of course, knowing that you have views dependent on a renamed table. |
As with other database maintenance, in VFP 3 the database must be open exclusively. The versions since VFP 5 don’t have this restriction, but no one else can have the table open when you make this change. We think that’s probably a reasonable restriction.
In VFP 7, if the database has Database Events
turned on, the BeforeRenameTable and AfterRenameTable events fire.
<a name=Example>RENAME TABLE MyTable TO YourTable</a>
Add Table, AfterRenameTable, BeforeRenameTable, DBSetProp(), Open Database, Rename