The Anubhav portal was launched in March 2015 at the behest of the Hon'ble Prime Minister for retiring government officials to leave a record of their experiences while in Govt service .
IDENTITY and SEQUENCE are both used to generate numeric values automatically in SQL databases, but they work differently and are suited for different scenarios.
Quick Comparison
Feature
IDENTITY
SEQUENCE
Tied to a table column
Yes
No
Reusable across tables
No
Yes
Generates values automatically on insert
Yes
Usually via NEXT VALUE FOR / nextval()
Custom control over generation
Limited
More flexible
Can generate numbers before insert
No
Yes
Reset/restart support
Limited
Easier
Standard SQL feature
Vendor-specific origins
ANSI SQL standard
1. IDENTITY
An IDENTITY column auto-generates values when rows are inserted.
Example in Microsoft SQL Server:
CREATE TABLE Employees (
EmployeeID INT IDENTITY(1,1),
Name VARCHAR(100)
);
Here:
First 1 = start value
Second 1 = increment
Inserted rows automatically get:
1, 2, 3, 4...
Characteristics
Bound directly to one table column
Mostly used for primary keys
Simpler setup
Less flexible
Common Databases Supporting IDENTITY
Microsoft SQL Server
PostgreSQL (GENERATED AS IDENTITY)
Oracle Database (12c+)
IBM Db2
2. SEQUENCE
A SEQUENCE is an independent database object that generates numbers.
Example in Oracle Database or PostgreSQL:
CREATE SEQUENCE emp_seq
START WITH 1
INCREMENT BY 1;
Use it:
INSERT INTO Employees(EmployeeID, Name)
VALUES(nextval('emp_seq'), 'John');
When to Use Which?
Use IDENTITY when:
Simple primary key generation
One table only
Minimal configuration needed
Standard CRUD applications
Use SEQUENCE when:
Multiple tables share numbering
Need custom numbering logic
Need numbers before insert
High scalability/concurrency
Enterprise workflows
Interview-Friendly Summary
IDENTITY is a table-bound auto-increment column, while SEQUENCE is an independent object that generates reusable numeric values with greater flexibility and control.
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
IDENTITYandSEQUENCEare both used to generate numeric values automatically in SQL databases, but they work differently and are suited for different scenarios.Quick Comparison
NEXT VALUE FOR/nextval()1. IDENTITY
An
IDENTITYcolumn auto-generates values when rows are inserted.Example in Microsoft SQL Server:
Here:
1= start value1= incrementInserted rows automatically get:
Characteristics
Common Databases Supporting IDENTITY
GENERATED AS IDENTITY)2. SEQUENCE
A
SEQUENCEis an independent database object that generates numbers.Example in Oracle Database or PostgreSQL:
Use it:
When to Use Which?
Use IDENTITY when:
Use SEQUENCE when:
Interview-Friendly Summary