SQL Oracle Java JSP JDBC PHP MORE

Oracle AUTO INCREMENT

In Oracle Auto-increment is used to generate a unique number when a new record is inserted into a table.

By default, the starting value for AUTO_INCREMENT is 1, and it will increment by 1 for each new record.

Oracle INSERT INTO Syntax

CREATE TABLE table_name
(
ID int NOT NULL AUTO_INCREMENT,
column_name1 data_type(size),
column_name2 data_type(size),
column_name3 data_type(size),
....
PRIMARY KEY (ID)
);

Oracle Auto Increment Example

CREATE TABLE Student
(
ID int NOT NULL AUTO_INCREMENT,
LastName varchar(50),
FirstName varchar(50),
RollNo varchar(50),
City varchar(50),
PRIMARY KEY (ID)
);

When we insert a new record into the "Student" table, we will NOT have to specify a value for the "ID" column (a unique value will be added automatically).