sqlbeginner

Sequence - Technique 10

Create and use sequences

sql
CREATE SEQUENCE IF NOT EXISTS invoice_number_seq START 1000;

INSERT INTO invoices (invoice_number, customer_id, total)
VALUES (nextval('invoice_number_seq'), 42, 199.99)
RETURNING invoice_number;

Use Cases

  • database operations
  • data management

Tags

Related Snippets

Similar patterns you can reuse in the same workflow.