Skip to main content
Tables are the fundamental building blocks of relational databases. They store your data in rows and columns, similar to spreadsheets but with powerful querying and relationship capabilities.

Creating Tables

You can create tables through the Dashboard, SQL Editor, or migrations.

Using the Dashboard

  1. Navigate to the Table Editor in your Supabase Dashboard
  2. Click New Table
  3. Enter the table name and add columns
  4. Configure primary keys and constraints
  5. Click Save

Using SQL

Using Migrations

For production workflows, use migrations to track schema changes:
supabase/migrations/20241205075911_create_movies_table.sql

Data Types

PostgreSQL supports a rich set of data types:

Common Data Types

Advanced Data Types

Primary Keys

Every table should have a primary key to uniquely identify each row.

Auto-incrementing Identity

UUID Primary Keys

Composite Primary Keys

Constraints

Constraints enforce data integrity rules.

NOT NULL Constraint

UNIQUE Constraint

CHECK Constraint

DEFAULT Values

Foreign Keys & Relationships

Foreign keys create relationships between tables.

One-to-Many Relationship

Many-to-Many Relationship

Foreign Key Actions

Inserting Data

Single Row Insert

Multiple Row Insert

Insert with Returning

Using JavaScript Client

Updating Data

Deleting Data

Views

Views provide reusable queries and can simplify complex data access.

Creating Views

Materialized Views

Materialized views cache query results for better performance:

Table Modifications

Add Columns

Modify Columns

Drop Columns

Rename Tables and Columns

Real Example from Supabase Source

Here’s a real table from the Supabase source code:

Best Practices

  • Use lowercase with underscores: user_profiles, not UserProfiles
  • Use plural nouns for tables: movies, users, orders
  • Avoid generic names: data, info, temp
Every table should have a primary key for uniqueness and indexing.
  • Use timestamptz for timestamps (includes timezone)
  • Use numeric for money (exact precision)
  • Use text for variable-length strings
  • Use jsonb for flexible structured data
Include created_at and updated_at columns for audit trails.
Protect your data with row-level security policies.

Next Steps

Functions

Create database functions for complex logic

Triggers

Automate actions with database triggers

Migrations

Manage schema changes with migrations

Indexes

Optimize query performance with indexes