Copy Structure, Copy Structure Extended, Create From
These commands let you duplicate the structure of an existing table, or create a similar but not identically structured table. They used to be extremely important commands, but newer commands do all the same things more easily.
Usage |
COPY STRUCTURE TO cTable [ DATABASE DatabaseName [ NAME LongTableName ] ] [ FIELDS cFieldList ] [ [ WITH ] CDX | PRODUCTION ] |
When you specify a database to add the new table to, COPY STRUCTURE doesn't preserve the rules, triggers, and so on in the new table that were associated with the original table. Null, code page, and long field name information is preserved. In VFP 3, the information was lost because you couldn't put the new table in a database. |
Example |
USE Orders * create a table to create archives COPY STRUCTURE TO OldOrders |
Usage |
COPY STRUCTURE EXTENDED TO cStructureTable [ DATABASE DatabaseName [ NAME LongTableName ] ] [ FIELDS cFieldList ] |
Column |
Type |
Meaning |
FIELD_NAME |
Character |
Field name |
FIELD_TYPE |
Single Character |
Field type—see CREATE TABLE for a list |
FIELD_LEN |
Numeric |
Field width |
FIELD_DEC |
Numeric |
Number of decimals |
FIELD_NULL |
Logical |
Does the field accept nulls? |
FIELD_NOCP |
Logical |
Do not allow code page translation? |
FIELD_DEFA |
Memo |
Default value for field |
FIELD_RULE |
Memo |
Field validation rule |
FIELD_ERR |
Memo |
Field validation text |
TABLE_RULE |
Memo |
Table validation rule |
TABLE_ERR |
Memo |
Table validation text |
TABLE_NAME |
Character |
Long name for the table |
INS_TRIG |
Memo |
Insert trigger code |
UPD_TRIG |
Memo |
Update trigger code |
DEL_TRIG |
Memo |
Delete trigger code |
TABLE_CMT |
Memo |
Table comment |
Usage |
CREATE cTable [ DATABASE DatabaseName NAME LongTableName ] FROM cStructureTable |
CREATE FROM doesn't ignore deleted records in the structure table. This means if you COPY STRUCTURE EXTENDED, then modify the table by deleting some of the records (that is, remove fields from the listing), you need to PACK the structure table before issuing CREATE FROM. Otherwise, your new table will have the fields you tried to remove. This bug is nothing new—older versions do the same thing. |
See Also |
AFields(), Alter Table, AfterAddTable, AfterCreateTable, BeforeAddTable, BeforeCreateTable, Copy To, Create Cursor, Create Table, Select-SQL |