Posts

Showing posts from April, 2026

Sequences in Oracle SQL

ABOUT SEQUENCES in Oracle SQL Definitions:- A Sequence is a DB object created to generate sequence numbers(integers) automatically. It's primary use to create auto-increment values for Surrogate Keys or Pimary Key Columns without manual intervention. Syntax: CREATE SEQUENCE [START WITH ] [INCREMENT BY ] [MAXVALUE ] [MINVALUE ] [CYCLE/NOCYCLE] [CACHE ]; OR CREATE SEQUENCE [START WITH n] [INCREMENT BY n] [MAXVALUE n | NOMAXVALUE] [MINVALUE n | NOMINVALUE] [CYCLE | NOCYCLE] [CACHE n | NOCACHE] [ORDER | NOORDER]; Example 1 :- CREATE SEQUENCE S1 START WITH 1 INCREMENT BY 1 MAXVALUE 5; using sequence :- -------------------------- CREATE TABLE STUDENT ( SID NUMBER(2), SNAME VARCHAR2(10) ); INSERT INTO STUDENT VALUES(S1.NEXTVAL , 'A'); INSERT INTO STUDENT VALUES(S1.NEXTVAL , 'B'); INSERT INTO STUDENT VALUES(S1.NEXTVAL , 'C'); INSERT INTO STUDENT VALUES...