You can set values in free and database table fields with Integer type to increment automatically.
Note: |
---|
Automatically incrementing field values is not supported for local, remote, or offline views. Activating automatically incrementing values in a field sets the field as read-only, and its values cannot be changed with an insert, update, or replace operation. For more information, see Autoincrementing Field Values in Tables. |
To set automatically incrementing values in a field
-
Open the table in the Table Designer.
-
On the Fields tab, select the field you want.
-
In the Type list, select Integer (AutoInc).
-
In the AutoIncrement area, type a start value for Next Value and an increment value for Step.
-
When you are finished, click OK.
Note: When you select the Integer (AutoInc) type for a field, the Default value box becomes unavailable. However, Visual FoxPro neither discards nor uses the default value. Any expressions in the Default value box remain when you change the field type to or from Integer (AutoInc). You can still use code such as DBGETPROP( ) to retrieve the default value for the field. If you want to use the value in the Default value box, you must first change the Integer (AutoInc) data type.
For more information, see Fields Tab, Table Designer.
To set automatically incrementing values in a field programmatically
-
When creating the table using the SQL CREATE TABLE command, include the AUTOINC clause.
-OR-
-
To edit an existing table, open the table with the USE command and then use the SQL ALTER TABLE command with the AUTOINC clause.
For more information, see CREATE TABLE - SQL Command or ALTER TABLE - SQL Command.