# SQL Studio

Browse, edit, and manage your PostgreSQL data directly from the DanubeData dashboard — no client to install, no credentials to copy.

## Overview

SQL Studio is an in-browser data studio included free with every managed PostgreSQL database:

- **Table editor** - Edit rows with staged, transactional commits
- **SQL editor** - Ad-hoc queries with a read-only safe mode
- **Schema tools** - Create-table builder, table operations, ER diagram
- **Objects browser** - Functions, triggers, views, roles, extensions, RLS policies
- **Zero install** - Runs entirely in your dashboard

Queries are executed by an isolated agent that runs inside your own tenant environment. Your database credentials never leave the platform.

## Availability

- SQL Studio works with **managed PostgreSQL instances only**. It is not available for MySQL or MariaDB.
- It is not available on demo accounts.
- There is no additional cost — Studio is included with every managed PostgreSQL plan.

## Opening SQL Studio

1. Go to **Databases** in the dashboard
2. Select your PostgreSQL instance
3. Open **SQL Studio**

If your instance hosts multiple databases, use the database selector in the top bar to switch between them.

## Browsing Data

- The sidebar lists all schemas and tables; type in the filter box to find a table quickly
- Click a table to open its rows in the data grid
- Click a column header to sort; click again to flip the direction
- Add per-column filters (`=`, `!=`, `<`, `>`, `LIKE`, `ILIKE`, `IS NULL`, …) with **+ Filter**
- Use the pager in the footer to move through large tables

## Editing Data

Editing is off by default. Flip the **Write mode** toggle in the top bar to enable it.

Changes are **staged locally** before anything touches the database:

- **Double-click a cell** to edit it. Use the **NULL** / **DEF** buttons to set the cell to `NULL` or the column default explicitly
- **+ Add row** appends a new row inline; columns you leave untouched use their database defaults
- The **delete** toggle marks a row for deletion (shown struck-through until you commit)
- Pending changes are highlighted, and the toolbar shows the count

Click **Commit** to apply everything in a **single database transaction** — if any change fails, nothing is written. Click **Discard** to drop all pending changes. A single commit can carry up to 500 staged changes.

Notes:

- Tables without a primary key are read-only in the grid (use the SQL editor instead)
- An **Insert (form)** drawer and a CSV import are also available for adding rows
- If you navigate away with pending changes, Studio asks whether to commit or discard them

## Table Operations

Right-click a table in the sidebar (Write mode required for anything that modifies the database):

- **Open** - View the table
- **Truncate** - Delete all rows (asks for confirmation)
- **Drop** - Delete the table; you must type the table's name to confirm
- **Rename** - Change the table name
- **Duplicate** - Copy the table structure, optionally with its data
- **Copy name** / **Copy CREATE statement** - Copy to clipboard (the CREATE statement is reconstructed from the catalog and is approximate)

Right-click an empty area of the sidebar for **New table** — a visual builder where you define columns, types, nullability, defaults, and the primary key.

## SQL Editor

The **SQL** tab runs ad-hoc statements:

- Queries run in a **read-only safe mode** by default — writes are rejected until you enable Write mode
- With Write mode on, destructive statements (for example `DROP` or `TRUNCATE`) ask for confirmation before running
- The editor executes **one statement per run**; for bulk data changes, use the table editor's staged commits or the CSV import
- Save frequently used queries as **snippets**, and re-open anything from your **history** with one click
- Export query results as **CSV** or **JSON**

## Schema Tools

- **Structure** tab - Columns, constraints, indexes, and foreign keys for the selected table
- **Diagram** tab - A live ER diagram of the schema: tables, columns, and foreign-key relationships, with pan and zoom
- **Database** tab - Browse functions, triggers, views, roles, extensions, and row-level-security policies, including their definitions

## Importing Data

Use **Import CSV** in the table footer (Write mode required) to bulk-load rows from a CSV file. The wizard lets you map CSV columns to table columns before inserting.

## Safety & Auditing

- Studio opens **read-only**; every write requires the explicit Write-mode toggle
- Row changes apply as one atomic transaction you can review and discard before committing
- Dropping a table requires typing its name
- **Every write is recorded** in your instance's query log (who, what, when, and the SQL that ran)
- Queries run through a per-tenant isolated agent — no shared query infrastructure between customers

## Next Steps

- [PostgreSQL Guide](https://docs.danubedata.ro/databases-postgresql)
- [Database Backups](https://docs.danubedata.ro/databases-backups)
- [Database Replicas](https://docs.danubedata.ro/databases-replicas)

Need help? Contact support through the dashboard.
