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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete rows and Drop FREE table

Status
Not open for further replies.

imox

Programmer
May 13, 2013
37
DE
Hello

Code:
CREATE TABLE temp FREE (idpr i(10))

INSERT INTO temp (idpr) VALUES (232323)
INSERT INTO temp (idpr) VALUES (78979)
INSERT INTO temp (idpr) VALUES (3865678)

DELETE FROM temp WHERE idpr = 78979


SELECT * FROM temp INTO CURSOR cur

SCAN 
MESSAGEBOX(idpr)
ENDSCAN

In this example the row should be removed, so I think. Can someone help me? And how can I drop this free table? When I try this in an example then it works but when I use this in my application in which I use a database then it doesn't work.

Thanks
 
1. SET DELETED ON, so the record is not read anymore.
2. You can't DROP a free table, simply ERASE the file(s), eg ERASE sometable.*

Bye, Olaf.
 
Make sure the table is not in use or open, otherwise, you will not be able to erase/delete it.



Ali Koumaiha
TeknoSoft Inc.
Michigan
 
Besides:

When using a free table to delete it later, don't do that, use a cursor, because a cursor not only automatically removes it's file from TEMP, it also supports features a free table does not, eg default values.

Code:
CREATE CURSOR temp (idpr n(10) DEFAULT 9999999999)
...is all it takes, no need to erase, simply ending the datasession or USE removes the cursor from memory.

CURSORs are faster in memory tables and unlike FREE tables not written to disc, unless they get so large they are swapped to TEMP. DBF("cursorname") will still show a file name and you can even APPEND FROM DBF("cursorname") as if the file existed, but it normally doesnt, unless you query or insert a giga byte into a cursor.

Bye, Olaf.

PS: And there is no type i(10), there is N(10) or I or int, VFP has no other integer field type than int as a 4 byte signed integer and it's max is therefore lower, about 2 billion. Thats 10 places, but the highest value digit can't get larger than 2, whereas an N(10) field can get as large as 10^10-1.
 
Not directly related to your question, but instead of this:

Code:
SCAN 
   MESSAGEBOX(idpr)
ENDSCAN

Do this:

Code:
BROWSE

As I think we've told you before, a Browse will allow you to see all the data at once, without having to stop on each one (as is the case with a message box). In addition, it will show you which records you have deleted (if you have DELETED set off).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I think the reason you can't delete the table is that the cursor is the table. Under certain circumstances, which your query meets, when you SELECT INTO a cursor, the cursor is just a filtered view of the table.

Read the section "VFP’s optimization trick" in
Tamar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top