In this post, I am creating an auto increment PRIMARY KEY using a custom sequence of the PostgreSQL.
PostgreSQL already provides two data types for auto increment id, serial (4 bytes) & bigserial (8 bytes).
When we apply serial or bigserial to the particular column, internally it creates a default sequence object for that column and automatically it generates auto increment value for that column.
We can also create custom sequence object in the PostgreSQL and it also requires in some situation where we do not want to use default sequence value.
First, Create a sequence object:Starting with 100 and increment by 10
CREATE SEQUENCE seq_MyCustom_Id
Create sample table:
CREATE TABLE tbl_SampleID
ID INTEGER PRIMARY KEY
,Name CHARACTER VARYING(50)
Use this sequence object and Insert sample data:
INSERT INTO tbl_SampleID
Please share your ideas and opinions about this topic with me, your contribution will add true value to this topic.
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.
If you like this post, then please share it with others.
Please follow dbrnd.com, I will share my experience towards the success of Database Research and Development Activity.
I put up a post every day, please keep reading and learning.
Discover Yourself, Happy Blogging !
Anvesh M. Patel.