Logo

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.

Usage

<a name=Usage>RENAME TABLE OldName TO NewName</a>

RENAME TABLE doesn’t affect the actual DBF file name, only the long name stored in the database. All the necessary DBC data is updated to reflect the new name, and you don’t have to redefine any of the indexes or relations.

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.

Example

<a name=Example>RENAME TABLE MyTable TO YourTable</a>

See Also

Add Table, AfterRenameTable, BeforeRenameTable, DBSetProp(), Open Database, Rename