Reputation: 11
How to make a copy with all the structure/schema from an existing table in FoxPro?
copy to
won't work
Upvotes: 1
Views: 2298
Reputation: 23867
There is no single command in VFP, that would copy with everything that an existing table might have. You have to define your requirement and what does your existing table have well.
For example, for simple copy with data you can use:
copy to NewTableName with cdx [Database dbName [Name tableNameInNewDb]]
This would copy the structure, along with indexes and existing data. However, it wouldn't copy other database level properties if any. You need to use cursorgetprop()\cursorsetprop(), dbgetprop()\dbsetprop() for others.
One way to do a complete copy, is first to get a programmatic version of your database and tables creation using (home()+'tools\gendbc\gendbc.prg') and then edit the generated code for your new table (and also to append the code from the old one).
Wish you initially explained us what do you meant by saying "copy to won't work".
PS: I noticed your question title is saying "make a blank copy". Then you might want to use:
copy to NewTableName with cdx for .F.
It would copy the structure and indexes but not the data. Other shortcomings still apply. If you didn't need the indexes then a simplier way would be:
select * from sourceTable where .F. into table targetTable
EDIT: As LAK pointed out, using WHILE instead of FOR would be faster on large tables:
copy to NewTableName with cdx while .F.
Upvotes: 4
Reputation: 650
It's
copy structure to newfile
or, alternatively,
copy to newfile for .f.
Upvotes: 2