Problem Statement
Contrast sequences and identity columns for generating primary keys. Mention flexibility and portability.
Explanation
Sequences are independent objects you can reuse across tables, set start and increment, and alter without touching table DDL. They work well when you need gaps handled explicitly or cross-table ordering.
Identity columns are convenient table-local generators. They reduce boilerplate but are less flexible to share or reset. Choose sequences for cross-table coordination or when your DBMS lacks uniform identity semantics; use identity for simple, per-table keys.
Code Solution
SolutionRead Only
CREATE SEQUENCE seq_id START WITH 1;
CREATE TABLE t (id BIGINT PRIMARY KEY DEFAULT nextval('seq_id'));Practice Sets
This question appears in the following practice sets:
