How to use auto-increment in oracle, mysql and sql server

Syntax for SQL Server The
following SQL statement defines the "ID" column in the "Persons" table as an auto-increment primary key field:
CREATE TABLE Persons
(
ID int IDENTITY(1,1) PRIMARY KEY,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255)
)

Syntax for MySQL The
following SQL statement defines the "ID" column in the "Persons" table as an auto-increment primary key field:
CREATE TABLE Persons
(
ID int NOT NULL AUTO_INCREMENT,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255),
PRIMARY KEY (ID)
)

syntax for Oracle
In Oracle, the code is slightly more complicated a little.
You must create an auto-increment field from a sequence object, which generates a sequence of numbers.
Use the following CREATE SEQUENCE syntax:
CREATE SEQUENCE seq_person
MINVALUE 1
START WITH 1
INCREMENT BY 1
CACHE 10
The above code creates a sequence object named seq_person that starts with 1 and increments by 1. This object caches 10 values ​​to improve performance. The cache option specifies how many sequence values ​​to store for faster access.
To insert a new record into the "Persons" table, we must use the nextval function (which retrieves the next value from the seq_person sequence):
INSERT INTO Persons (ID,FirstName,LastName)
VALUES (seq_person.nextval,'Lars', 'Monsen')

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326272429&siteId=291194637