Aracılığıyla paylaş


How to: Name Fields

You specify names for fields as you build a table. For free tables, field names can be up to 10 characters long. For database tables, field names can be up to 128 characters long.

Note

If you remove a table from a database, the long field names in a table are truncated to 10 characters. For more information, see Field Creation.

To name a table field

  1. Open the table in the Table Designer.

  2. Click the Fields tab.

  3. In the Name box, type a name for the field.

For more information, see How to: Open Tables (Visual FoxPro) and Fields Tab, Table Designer.

To name a table field programmatically

  • When creating the table using the SQL CREATE TABLE command, specify the field name.

    -OR-

  • To edit an existing table, open the table with the USE command and then use the SQL ALTER TABLE command.

For more information, see CREATE TABLE - SQL Command or ALTER TABLE - SQL Command.

For example, the following code creates and opens a table named Customer with three fields, Cust_ID, Company, and Contact using the CREATE TABLE command:

CREATE TABLE Customer (Cust_ID C(6), Company C(40), Contact C(30))

In the example, C(6) indicates the field contains Character data and has a field width of 6 characters. For more information, see How to: Choose Data Types.

The following code adds fields to an existing table using the SQL ALTER TABLE command:

ALTER TABLE Customer ;
   ADD COLUMN (Company C(40), Contact C(30))

Renaming Fields

You can rename existing table fields.

To rename a table field

  1. Open the table in the Table Designer.

  2. In the Name box on the Fields tab, insert the cursor in the field you want and type the new name for the field.

For more information, see Fields Tab, Table Designer.

To rename a table field programmatically

  • Use the SQL ALTER TABLE command with the RENAME COLUMN clause.

For more information, see ALTER TABLE - SQL Command.

For example, the following code renames the Company field in the Customer table using the SQL ALTER TABLE command:

ALTER TABLE Customer RENAME COLUMN Company TO Company_LongName

See Also

Tasks

How to: Edit Table Structure

How to: Choose Data Types

Concepts

Field Creation

Other Resources

Working with Fields

Working with Tables (Visual FoxPro)