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!

VFP 6 Replicating a table 4

Status
Not open for further replies.

eric43

Programmer
Apr 29, 2005
94
AU
I have a table with many records - I wish to create an empty temporary table with the same structure with no records.

This will be needed to work whether the new table is in use and hasn't been closed or not.

Is this possible?

Thanks

Eric
 

Eric,

Here's one possibility:

Code:
SELECT * FROM MyTable INTO TABLE NewTable WHERE .F.

Or, change TABLE to CURSOR in the above. That way, the new table will be truly temporary, and will disappear after you close it.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
All I'd add is that the new table will appear in your default folder unless you specify a path. You might find you've created a new table in C:\PROGRAM FILES\MICROSOFT VISUAL FOXPRO 9\ and that's not a good idea.

Geoff Franklin
 
There's actually a VFP command that does what you want, much faster than SELECT on a large table:

COPY STRUCTURE TO (lcTempFileName)

You can write code to test if the source file is already open and open it if not, then make it the currently selected file and issue the COPY STRUCTURE. You can specify the full path in lcTempFileName. The cloned file is not opened afterwards, so you have to USE it.


Mike Krausnick
Dublin, California
 
Hmm - thanks Mike - I now seem to remember this from Clipper days too.

Eric
 

And you can also

COPY TO NewTable FOR .F. WITH CDX

which is very handy if you have a lot of tags and want to replicate all of them, too.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top