Rename Table

This command lets you change the long name of a table in a database.

Usage

RENAME TABLE OldName TO NewName
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

RENAME TABLE MyTable TO YourTable

See Also

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


Back to Table of Contents

Copyright © 2002-2018 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. Click for license .