COPY STRUCTURE EXTENDED Command
Creates a new table with fields containing the structure of the currently selected table.
COPY STRUCTURE EXTENDED TO FileName
[DATABASE DatabaseName [NAME LongTableName]] [FIELDS FieldList]
Parameters
FileName
Specifies the new table to create.DATABASE DatabaseName
Specifies a database to which the new table is added.NAME LongTableName
Specifies a long name for the new table. Long names can contain up to 128 characters and can be used instead of short file names in the database.FIELDS FieldList
Specifies that only the fields in FieldList are included in a record in the new table. If you omit FIELDS FieldList, all fields have a record in the new table.
Remarks
Information about each field in the currently selected table is copied to a record in the new table. The structure of the new table has a fixed format and consists of 18 fields. The following table lists the names of the fields and their contents.
Field |
Field type |
Contents |
---|---|---|
FIELD_NAME |
Character |
Field names from selected table (128 characters wide) |
FIELD_TYPE |
Character |
Field types: Blob Character Currency Date DateTime Double Float General Integer Logical Memo Numeric Varchar and Varchar (Binary) Varbinary |
FIELD_LEN |
Numeric |
Field widths |
FIELD_DEC |
Numeric |
Number of decimal places in numeric fields |
FIELD_NULL |
Logical |
Field null value support |
FIELD_NOCP |
Logical |
Code page translation not allowed (character and memo fields only) |
FIELD_DEFA |
Memo |
Field default values |
FIELD_RULE |
Memo |
Field validation rules |
FIELD_ERR |
Memo |
Field validation text |
TABLE_RULE |
Memo |
Table validation rule |
TABLE_ERR |
Memo |
Table validation text |
TABLE_NAME |
Character |
Long table name (first record only) |
INS_TRIG |
Memo |
Insert trigger expression (first record only) |
UPD_TRIG |
Memo |
Update trigger expression (first record only) |
DEL_TRIG |
Memo |
Delete trigger expression (first record only) |
TABLE_CMT |
Memo |
Table comment (first record only) |
FIELD_NEXT |
Numeric |
Next value for AUTOINC field, if enabled. |
FIELD_STEP |
Numeric |
Step value for AUTOINC field. If value is 0, autoincrementing is not enabled for the field. |
The width of the FIELD_NAME field is 10 characters in previous versions of Visual FoxPro, FoxPro for Windows, and FoxPro for MS-DOS. To use CREATE FROM with a table created by COPY STRUCTURE EXTENDED in Visual FoxPro 5.0 and earlier, you must change the width of the FIELD_NAME field to 10 characters. Some field types are not supported in Visual FoxPro 3.0 and earlier versions.
If fields in the source table use autoincrementing, FIELD_STEP is a nonzero value.
You can modify the newly created table and use the CREATE FROM command to create a new table with a different structure. The COPY STRUCTURE and CREATE FROM commands allow you to programmatically change the structure of a table.
Example
The following example displays the structure of the Orders table, copies the structure extended to a Temp table, browses Temp, creates a table called Backup from Temp, and displays the structure of Backup.
CLOSE DATABASES
OPEN DATABASE (HOME(2) + 'Data\testdata')
USE Orders && Opens Orders table.
CLEAR
DISPLAY STRUCTURE
WAIT WINDOW 'Structure of the Orders table' NOWAIT
COPY STRUCTURE EXTENDED TO Temp
USE Temp
WAIT WINDOW 'The Temp table - 1 row per field in orders' NOWAIT
BROWSE
CREATE Backup FROM Temp
USE Backup
DISPLAY STRUCTURE
WAIT WINDOW 'Backup.dbf has the same structure as Orders' NOWAIT
USE
DELETE FILE Temp.dbf
DELETE FILE Backup.dbf
See Also
Concepts
Autoincrementing Field Values in Tables