Tech Tip: Using Alter Table to create Auto Increment/Generate in a new Field
PRODUCT: 4D | VERSION: 13.4 | PLATFORM: Mac & Win
Published On: January 3, 2014
The ALTER TABLE command has the ability to create a field in a table to enable the auto increment on an Integer (Integer/Long Integer/Integer 64) and/or auto generate on a UUID through SQL. Enabling the attribute of auto increment/generate in the command can only be done during the time of creating the field only. It would mean that an exsisting field cannot enable the attribute.
Example of creating a field and auto incrementing an Integer:
C_TEXT($textQuery;$tableName;$fieldName;$fieldType) $tableName:="Table_1" $fieldName:="Age" $fieldType:="INT" $textQuery:="ALTER TABLE "+$tableName+" ADD "+ Begin SQL EXECUTE IMMEDIATE: $textQuery; END SQL |
Result of the code executed in red:
Example of creating a field and auto generating a UUID:
$tableName:="Table_1" $fieldName:="ID" $fieldType:="UUID" $textQuery:="ALTER TABLE "+$tableName+" ADD "+$fieldName+" "+$fieldType+" AUTO_GENERATE";" Begin SQL EXECUTE IMMEDIATE: $textQuery; End SQL |
Result of the code executed in red:
See Also: