7099bd3cde
Rewrite "Seeing the SQL behind a command" with the learning framing, a grounded ALTER TABLE example, and the sql-echo cast. Drop the "multiple result tabs" promise (won't-do on main) and the planned `hint`-command note (superseded by the hint panel).
88 lines
2.9 KiB
Plaintext
88 lines
2.9 KiB
Plaintext
---
|
|
title: Simple and advanced modes
|
|
description: How the playground's two input modes differ, how to switch, and the one-line escape hatch.
|
|
sidebar:
|
|
order: 3
|
|
---
|
|
|
|
import Demo from '../../../components/Demo.astro';
|
|
|
|
The playground has two input modes. You can do everything a beginner needs
|
|
in **simple mode**, and reach for **advanced mode** when you want full SQL.
|
|
|
|
<Demo src="/casts/modes.cast" title="The same command in both modes — advanced mode also shows the SQL it runs for you." />
|
|
|
|
## Simple mode (the default)
|
|
|
|
Simple mode is a friendly, keyword-based command language designed for
|
|
learning. Commands read close to English:
|
|
|
|
```rdbms
|
|
create table authors with pk author_id(serial)
|
|
show data authors
|
|
```
|
|
|
|
Simple mode accepts these learning commands plus the app-level commands
|
|
(like `save`, `undo`, and `help`). If you type raw SQL here, the playground
|
|
gently points you at advanced mode instead of failing silently.
|
|
|
|
## Advanced mode (SQL)
|
|
|
|
Advanced mode accepts standard SQL — `SELECT`, `INSERT`, `CREATE TABLE`, and
|
|
more — alongside the same app-level commands:
|
|
|
|
```sql
|
|
select title, published from books where published >= 2000 order by published;
|
|
```
|
|
|
|
Switch modes with the `mode` command:
|
|
|
|
```rdbms
|
|
mode advanced
|
|
mode simple
|
|
```
|
|
|
|
The mode you leave a project in is remembered and restored the next time you
|
|
open it, so a project set up for SQL practice reopens in advanced mode.
|
|
|
|
## The one-line escape
|
|
|
|
When you are in simple mode and want to run a single SQL statement without
|
|
switching, prefix the line with a colon:
|
|
|
|
```rdbms
|
|
:select count(*) from books
|
|
```
|
|
|
|
That runs just this one line as SQL; you stay in simple mode afterwards.
|
|
|
|
## Seeing the SQL behind a command
|
|
|
|
Run a **simple-mode command while in advanced mode** and the playground prints
|
|
the equivalent SQL beneath it, tagged `Executing SQL:`. This is one of the most
|
|
useful ways the playground teaches: you write the friendly, readable command,
|
|
and immediately see the real SQL statement it stands for — the same statement
|
|
you could have typed yourself.
|
|
|
|
It turns every command into a small SQL lesson. Add a column the easy way and
|
|
watch the `ALTER TABLE` it maps to:
|
|
|
|
```rdbms
|
|
add column to books: title (text)
|
|
```
|
|
|
|
```
|
|
Executing SQL: ALTER TABLE books ADD COLUMN title text
|
|
```
|
|
|
|
The payoff grows with the command. A single `create m:n relationship` — the
|
|
one-line way to
|
|
[link two tables many-to-many](/reference/relationships/#many-to-many-relationships)
|
|
— expands to an entire junction table: two foreign-key columns, a compound
|
|
primary key, and two cascading foreign keys, all spelled out in the echo.
|
|
|
|
<Demo src="/casts/sql-echo.cast" title="Simple-mode commands run in advanced mode each echo the SQL they run — ending with the m:n command expanding to a full junction table." />
|
|
|
|
Because the echo is exactly what runs, it doubles as a recipe: read it, copy
|
|
it, tweak it, and run your own version in advanced mode.
|