Menu

PostgreSQL
📰

PostgreSQL

DEV Community: postgres·Vasanthakumari N·1 day ago
#NO7r0wnR
#devtopostgresql#devto#dev#table#primary
Reading 0:00
15s threshold

Auto Generate?

In PostgreSQL, Auto Generate usually means automatically generating values for a column, such as an ID.

You can use SERIAL or GENERATED AS IDENTITY.

Example: Using SERIAL

CREATE TABLE student ( id SERIAL PRIMARY KEY , name VARCHAR ( 50 ) , age INT ) ;

Enter fullscreen mode

Exit fullscreen mode

Two ways to auto-generate IDs

SERIAL --> id SERIAL

Identity --> id INT GENERATED ALWAYS AS IDENTITY

Primary Keys

A primary key constraint indicates that a column, or group of columns, can be used as a unique identifier for rows in the table. This requires that the values be both unique and not null.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.