What is SERIAL type?

In the context of databases, the SERIAL type is a special data type used in PostgreSQL to create auto-incrementing integer columns. It is commonly used for primary keys. When you define a column as SERIAL, PostgreSQL automatically creates a sequence and sets the default value of the column to the next value from that sequence.

Here’s an example of how to use the SERIAL type in a table definition:

CREATE TABLE users (
    id SERIAL PRIMARY KEY,
    username VARCHAR(50) NOT NULL,
    email VARCHAR(100) NOT NULL
);

In this example, the id column will automatically increment with each new row added to the users table.

0 Comments

no data
Be the first to share your comment!