Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting data from my table

Status
Not open for further replies.

tforr

Programmer
Aug 14, 2003
181
GB
Hi I have used the following code to delete the data from my employees table.

"delete from employees.dbf

set deleted on

clear all"

Is this right or am I doing something wrong because the data seems to be deleted but when I close the table and application (VFP 6), re-open it and select * from the employees table, the data is back but and marked for deletion. How can I permanently delete all the records from the table.

Thanks and kind regards,

Tom
 
Tom,

The DELETE command only marks the records for deletion; it does not physically delete them. When you SET DELETED ON, the deleted records will be invisible, but they are still in the table.

When you came back into VFP, DELETED is presumably set off again (this is the default), so you can still see the deleted records.

The CLEAR ALL command has no effect on any of this.

To physically remove all the records, you need to do a PACK. You can also delete all the records and do a PACK in one go by using ZAP. (Both those commands require you to open the table with exclusive use.)

Hope that helps.

Mike


Mike Lewis
Edinburgh, Scotland
 
Hi

TO permanently delete all records, you have to issue the command PACK


SELECT 0
USE Employess EXCL
ZAP
will do the trick.

OR
SELECT 0
USE Employess EXCL
DELETE ALL
PACK

will do it.

If you are not in an exclusive mode.. then

Simply DELETE ALL
and wait for a later occassion when you go EXCLUSIVE and us ethe PACK command to deop all those deleted records.

In the mean time, to avoid deleted records.,
SET DELETED ON along with your SET commands at the beginning. In your above code, since you are issuing SET DELETED ON after deleting, it appears deleted. When you restart, this SET DELE ON is not in place and so you see all the records. Now if you SELECT * FROM employees, even the deleted records will be selected.

SET DELETED ON
SELECT * from Employees will show the undeleted records.
SELECT * FROM employees FOR !DELETED() will give undeleted records only.

SO a number of ways to do the same thing. :)







____________________________________________
ramani - (Subramanian.G) :)
When you ask VFP questions, please add VFP version.
 
Thanks for the help.

Brilliant forum.

Regards,

Thomas.
 
Hi Tom,

In the old days, when file header corruption was more of a problem, we would typically create a new file, delete the old one, then rename the new one, rather than use ZAP or DELETE ALL, PACK:

use temp
copy stru to temp2
use
delete file temp.dbf
rename temp2.dbf to temp.dbf

Of course, they were all stand-alone files then, no database containers to worry about. Nowadays, I'd go with ZAP.

BTW, just in case you weren't aware, you were using a SQL command to delete your records, not a native FoxPro command. Six 'a one, half-dozen of the other! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top