Syntax for MySQL
By default, the starting value for AUTO_INCREMENT is 1, and
it will increment by 1 for each new record.
CREATE TABLE Persons
(
P_Id int NOT NULL AUTO_INCREMENT,
FirstName varchar(255),
PRIMARY KEY (P_Id)
ALTER TABLE Persons AUTO_INCREMENT=100
To start value initially from
100.
Syntax for SQL Server
The following SQL statement defines the "P_Id"
column to be an auto-increment primary key field in the "Persons"
table:CREATE TABLE Persons
(
P_Id int PRIMARY KEY IDENTITY,
FirstName varchar(255),
)
The MS SQL Server uses the IDENTITY keyword to perform an
auto-increment feature.
By default, the starting value for IDENTITY is 1, and it
will increment by 1 for each new record.
To specify that the "P_Id" column should start at
value 10 and increment by 5, change the identity to IDENTITY(10,5).