Home

SQL Keywords: COUNTER

  

Introduction

The COUNTER or AUTOINCREMENT keyword is used to create a column whose values would be automatically set in an incremental manner. Here is an example:

CREATE TABLE Contractors(ContractorID COUNTER,
                         FullName TEXT NOT NULL);

By default, when you apply the COUNTER or the AUTOINCREMENT data type, when the user creates the first record, the field under the auto-incrementing value receives a number of 1. If the user creates a second record, the auto-incrementing value receives a number of 1, and so on. If you want, you can make the first record receive a number other than 1. You can also make it increment to a value other than 1. To apply this feature, the COUNTER and the AUTOINCREMENT types use a seed in their parentheses: COUNTER(x,y) or AUTOINCREMENT(x,y). The x value represents the starting value of the records. The y value specifies how much would be added to a value to get the next. Here is an example:

CREATE TABLE Contractors(ContractorID AUTOINCREMENT(5, 10),
                         FullName TEXT NOT NULL);

Home Copyright © 2009 FunctionX