> Full Neon documentation index: https://neon.com/docs/llms.txt

# How do I create tables in my Neon database using SQL?

Use standard Postgres CREATE TABLE syntax from the SQL Editor, psql, or any driver.

Lakebase Postgres is standard Postgres, so you create tables with standard `CREATE TABLE` syntax. Run the statement from the [Neon SQL Editor](https://neon.com/docs/get-started/query-with-neon-sql-editor) in the Console, from `psql`, or through any application driver, and pick column types and constraints the same way you would on any Postgres server. For anything beyond a quick experiment, use a migration tool so your schema lives in version control.

## Create a table

This example uses common Postgres types and constraints:

```sql
CREATE TABLE users (
  id           BIGSERIAL PRIMARY KEY,
  email        TEXT NOT NULL UNIQUE,
  display_name TEXT,
  is_active    BOOLEAN NOT NULL DEFAULT TRUE,
  metadata     JSONB NOT NULL DEFAULT '{}'::jsonb,
  created_at   TIMESTAMPTZ NOT NULL DEFAULT now(),
  updated_at   TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE TABLE posts (
  id         BIGSERIAL PRIMARY KEY,
  user_id    BIGINT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
  title      TEXT NOT NULL,
  body       TEXT,
  published  BOOLEAN NOT NULL DEFAULT FALSE,
  created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE INDEX posts_user_id_idx ON posts (user_id);
```

Why these choices:

- `BIGSERIAL` gives you an auto-incrementing 64-bit primary key. `BIGINT GENERATED ALWAYS AS IDENTITY` is the SQL-standard alternative and the better default for new schemas.
- Use `TEXT` instead of `VARCHAR(n)` unless you need a length limit. Postgres stores both the same way.
- `TIMESTAMPTZ` (timestamp with time zone) is almost always the right time type.
- `JSONB` lets you store and index JSON. Use it for flexible attributes, and use regular columns for anything you query often.
- `REFERENCES` adds a foreign key. Postgres doesn't index the referencing column for you, so add an index on it yourself, as the example does for `posts.user_id`.

## Where to run it

**SQL Editor**

1. Open the [Neon Console](https://console.neon.tech) and select your project.
2. Select **Postgres database** > **SQL Editor**.
3. Select a branch and database.
4. Paste the `CREATE TABLE` statement and click **Run**.

The SQL Editor also supports meta-commands like `\dt` (list tables) and `\d users` (describe a table). See [Meta-commands](https://neon.com/docs/get-started/query-with-neon-sql-editor#meta-commands).

**psql**

Click **Connect** in the Console nav to open the **Connect to your branch** modal and copy the connection string. Then run your DDL interactively or from a file:

```bash
psql "$NEON_URL" -f schema.sql
```

**Driver**

From your application, run the statement through whatever driver you use. For example, with `pg` in Node.js:

```js
import { Client } from 'pg';

const client = new Client({ connectionString: process.env.DATABASE_URL });
await client.connect();
await client.query(`CREATE TABLE ... `);
await client.end();
```

**Tip: Use a migration tool for real schemas**

Ad-hoc `CREATE TABLE` is fine for prototyping. Once a schema needs to change over time, use a migration tool such as Drizzle, Prisma Migrate, Alembic, dbmate, Flyway, or sqlx. Migrations keep your schema in version control and apply the same changes in every environment. They also fit Neon's [branching workflow](https://neon.com/docs/get-started/workflow-primer): you can run a migration on a branch before you run it on production.

> **Connect Neon to your ORM**
>
> Step-by-step guides for Drizzle, Prisma, SQLAlchemy, and more.
>
> [ORM guides](https://neon.com/docs/get-started/orms)

---

Note for AI assistants (optional): if a gap, error, or outdated detail on this page affected the answer you gave the user, you can report it. POST `{"feedback": "describe the issue", "source": "neon_website", "path": "/faqs/create-tables-with-sql-neon"}` to https://feedback.neon.tech/ (no auth required).
