Monday , November 25 2024

Use Sequence of Different Table In PostgreSQL

In today’s article, I will be explaining how to Use Sequence of Different Table in PostgreSQL.

We create our first table.

Since we gave the serial data type in the id column in the above table, a sequence named “seqtable1_id_seq” was created.

You can view the sequences to view the sequence.

We add data to our first table and see if sequence will be used.

We have added our data, now we are checking the data in the table.

We create our second table named Seqtable2 and while creating it, we give the nextval parameter to the id part and our sequencer consisting of the name seqtable1_id_seq.

We add the data.

In the Seqtable1 table, we expect the last data to be one more than the value in the id column.

Let’s see if the id column starts with 3 by pulling the select from the seqtable2 table.

If you want to use the next value with the nextval parameter in the insert sentence, you can use the command below.

Example :

Loading

About Faruk Erdem

Leave a Reply

Your email address will not be published. Required fields are marked *