How to Create auto increment column in oracle

--Creating student table 
 
Create table tblStudent 
St_ID number not null, 
 Name varchar(50), 
 Email varchar(50), 
 Contact varchar(50)
 ) 

--Creating sequesnce table for auto increment 

Create sequence St_ID start with 1; 

 --creating trigger for auto update incremental ID into column 

CREATE OR REPLACE TRIGGER tgrStudent BEFORE INSERT ON tblStudent FOR EACH ROW BEGIN SELECT St_ID.NEXTVAL INTO :new.St_ID from dual; END; 

Insert into tblStudent(Name, Email,Contact) values('Praveen','itspraveenkp@gmail.com','889----9297'); Select * from tblStudent;

0 Comments