AutoCloseTables

Drop Table, Drop View

These two commands let you remove tables and views from a database, as well as delete free tables. We could do all of this before with other commands, but DROP is the ANSI-standard keyword for removing things.

Usage

DROP TABLE TableName | FileName | ? [ RECYCLE ] DROP VIEW ViewName
The syntax for DROP TABLE reminds us of George Carlin's immortal question, "Why are there three?" The answer is that you can delete a table that's contained in a database by simply giving the table's name, or delete a free table by specifying its path and name or avoid having to remember names by specifying ?.

DROP TABLE changes its behavior depending on whether there's a current database. If a database is set, it assumes you're handing it the name of a table in the database (or want to choose one, if you put ?). If you specify a free table in that case, you get an error message, even if you give its complete path and file name. The command just isn't smart enough to understand that you couldn't care less about the open database.

When you issue DROP TABLE ?, if there's a database set, you get a little dialog box that lets you choose a table from the database. If no database is current, you get the standard Windows Save dialog with a caption of "Delete" and the list limited to tables. Pretty smart. Of course, it would be even nicer if you could switch from database-container tables to free tables or choose a database and then see its tables.

The RECYCLE clause gives you the chance to go back again, sort of. If you add it, the table (and its associated index and memo files) lands in the Recycle Bin rather than going off into file heaven. You can restore them in the usual way. However, the result is as if you'd removed the table from the database with the REMOVE TABLE command—all the stuff that applies only to database tables (like rules and triggers and format and InputMask, and so forth) is lost.

In VFP 5, if the table you specify is the parent of a persistent relation, VFP's reaction to DROP TABLE depends on the case you use in the command, of all things. If you specify the table in all lowercase, instead of removing it from the database and deleting it, VFP gives you an error telling you it's "referenced" in a relation. Yeah, so what? But wait, it gets better. If you include even one uppercase letter in the name, the DROP TABLE command works. The table and relation are removed from the database, and the table is deleted. In VFP 6 and later, the situation is much simpler. It just doesn't let you drop a table that's referenced in a relation. We're not sure if that's a good thing or a bad thing, but we know for sure that it's not a documented thing.


DROP VIEW is a lot easier to deal with. Give it a view name in the current database and it removes the view from the database. There's no RECYCLE clause here, and unlike choosing a view and pressing Delete in the Database Designer, there's no confirmation dialog, so be careful.

Help says DROP VIEW is just another name for DELETE VIEW. So why doesn't DROP VIEW accept ? to let us choose a view to delete? DELETE VIEW does.


In VFP 7, dropping a table belonging to a database that has database events turned on fires the BeforeDropTable and AfterDropTable events. As you can probably guess, the BeforeDropView and AfterDropView events fires when a view is dropped.

Example

* Careful - these commands will remove data from the sample  * applications - try this on a copy! OPEN DATABASE TasTrade DROP TABLE Setup SET DATA TO DROP TABLE \MyData\MyTable SET DATA TO TasTrade DROP VIEW top25cust

See Also

Add Table, AfterDropTable, AfterDropView, BeforeDropTable, BeforeDropView, Create SQL View, Delete File, Delete View, Erase, Remove Table


View Updates

Copyright © 2002 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. All Rights Reserved.



Hacker's Guide to Visual FoxPro 7. 0
Hackers Guide to Visual FoxPro 7.0
ISBN: 1930919220
EAN: 2147483647
Year: 2001
Pages: 899

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net