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 in place of short file names in the database. - FIELDS FieldList
Specifies that only the fields specified 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 is fixed in format and consists of sixteen fields. The following table lists the names of the 16 fields and their contents.
Field | Field type | Contents |
---|---|---|
FIELD_NAME | Character | Field names from selected table (128 characters wide) |
FIELD_TYPE | Character | Field types:C = CharacterY = CurrencyN = NumericF = FloatI = IntegerB = DoubleD = DateT = DateTimeL = LogicalM = MemoG = General |
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) |
You can modify the newly created table and then use CREATE FROM to create a new table with a different structure. COPY STRUCTURE and CREATE FROM allow you to programmatically change the structure of a table.
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. Note that some field types are not supported in Visual FoxPro 3.0 and earlier versions.
Example
The following example displays the structure of the orders
table, copies the structure extended to a temp
table, browses temp
, creates a backup
table 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