Skip to main content

SQL Editor

The SQL editor is the heart of TablePro, providing a powerful environment for writing and executing SQL queries with syntax highlighting, intelligent autocomplete, and multi-query support.
SQL Editor

Editor Features

Syntax Highlighting

The editor provides real-time syntax highlighting for:
  • Keywords: SELECT, FROM, WHERE, JOIN, etc. (pink)
  • Strings: Single and double-quoted strings (green)
  • Numbers: Numeric literals (blue)
  • Comments: Single-line (--) and multi-line (/* */) comments (gray)
  • Functions: Built-in SQL functions
  • Identifiers: Table and column names

Line Numbers

Line numbers are displayed by default, making it easy to:
  • Reference specific lines in error messages
  • Navigate large queries
  • Communicate about code with others
Toggle line numbers in Settings > Editor > Show Line Numbers.

Current Line Highlighting

The current line is subtly highlighted to help you track your cursor position, especially useful in long queries.

Writing Queries

Single Query

Write and execute a single query:
SELECT * FROM users WHERE active = true;
Press Cmd+Enter to execute.

Multiple Queries

Write multiple queries separated by semicolons:
SELECT * FROM users LIMIT 10;
SELECT COUNT(*) FROM orders;
SELECT name, email FROM customers WHERE country = 'US';
Place your cursor in any statement and press Cmd+Enter to execute just that statement.

Selecting and Executing

Select text in the editor and press Cmd+Enter to execute only the selection. If your selection contains multiple statements (separated by semicolons), they are executed sequentially within a transaction:
  • Statements run in order, one at a time
  • If any statement fails, execution stops and all changes are rolled back
  • The error message indicates which statement failed (e.g. “Statement 3/5 failed: …”)
  • Results from the last SELECT statement are displayed in the data grid
  • Each statement is recorded individually in query history
This is useful for running SQL dumps, migrations, or batches of related statements:
DROP TABLE IF EXISTS users;
CREATE TABLE users (id INT PRIMARY KEY, name VARCHAR(100));
INSERT INTO users VALUES (1, 'Alice'), (2, 'Bob');
SELECT * FROM users;

Autocomplete

TablePro provides intelligent SQL autocomplete that understands your database schema.

Triggering Autocomplete

Autocomplete appears automatically as you type, or you can trigger it manually:
  • Start typing a keyword, table name, or column name
  • Press Escape to dismiss the popup
  • Use arrow keys to navigate suggestions
  • Press Enter or Tab to accept a suggestion
Autocomplete

What Gets Suggested

ContextSuggestions
After SELECTColumn names, *, functions
After FROMTable names, schema names
After JOINTable names
After WHEREColumn names from selected tables
After . (dot)Columns from the specified table
Start of statementSQL keywords

Schema-Aware Completion

Autocomplete is context-aware and understands your schema:
SELECT u.  -- Shows columns from 'users' table aliased as 'u'
FROM users u
JOIN orders o ON u.id = o.  -- Shows columns from 'orders' table

SQL Keywords

Common SQL keywords are suggested based on context:
  • After SELECT: DISTINCT, TOP, ALL
  • After FROM: JOIN, LEFT JOIN, INNER JOIN, WHERE
  • After WHERE: AND, OR, NOT, IN, LIKE, BETWEEN

Query Execution

Running Queries

ActionShortcutDescription
Execute queryCmd+EnterRuns query at cursor, or all selected statements
Explain queryOption+Cmd+EShow the execution plan for the query at cursor

Query Results

Results appear in the data grid below the editor:
  • Row count and execution time are shown
  • Results are paginated for large datasets
  • Click column headers to sort

Explain Query

Use the Explain Query feature to view the execution plan for your query, helping you understand how the database will execute it and identify performance bottlenecks. To explain a query:
  • Click the Explain button in the editor toolbar, or
  • Press Option+Cmd+E, or
  • Use the menu: Query > Explain Query
TablePro automatically uses the correct syntax for your database:
DatabaseSyntax Used
MySQL / MariaDBEXPLAIN <query>
PostgreSQLEXPLAIN <query>
SQLiteEXPLAIN QUERY PLAN <query>
The execution plan results appear in the data grid below the editor, showing index usage, join strategies, and estimated row counts.
Run Explain before executing expensive queries to verify they use the expected indexes and join strategies.

Error Handling

When a query fails:
  1. The error message appears below the editor
  2. Line numbers may be highlighted if the error references a specific line
  3. Read the error message for details on what went wrong
Query error

Editor Settings

Customize the editor in Settings > Editor:

Font Settings

SettingOptionsDefault
Font FamilySystem Mono, SF Mono, Menlo, Monaco, Courier NewSystem Mono
Font Size11-18 pt13 pt

Display Settings

SettingDescriptionDefault
Show Line NumbersDisplay line numbersOn
Highlight Current LineSubtle highlight on cursor lineOn
Word WrapWrap long linesOff

Indentation Settings

SettingOptionsDefault
Tab Width2, 4, 8 spaces4
Auto IndentAutomatic indentationOn

Tips and Tricks

Formatting Queries

For better readability, format complex queries with indentation:
SELECT
    u.id,
    u.name,
    u.email,
    COUNT(o.id) as order_count
FROM users u
LEFT JOIN orders o ON u.id = o.user_id
WHERE u.created_at > '2024-01-01'
    AND u.status = 'active'
GROUP BY u.id, u.name, u.email
HAVING COUNT(o.id) > 5
ORDER BY order_count DESC
LIMIT 100;

Using Comments

Add comments to document your queries:
-- Get active users with recent orders
SELECT u.name, COUNT(o.id) as orders
FROM users u
JOIN orders o ON u.id = o.user_id
WHERE u.active = true
    AND o.created_at > CURRENT_DATE - INTERVAL '30 days'
GROUP BY u.name;

/*
 * Multi-line comment
 * Useful for longer explanations
 */

Quick Table Exploration

To quickly explore a table’s structure and data:
-- View table structure (MySQL)
DESCRIBE users;

-- View table structure (PostgreSQL)
\d users

-- Sample data
SELECT * FROM users LIMIT 10;

-- Row count
SELECT COUNT(*) FROM users;

Using Aliases

Use table aliases for cleaner, more readable queries:
-- Without aliases (verbose)
SELECT users.name, orders.total
FROM users
JOIN orders ON users.id = orders.user_id;

-- With aliases (cleaner)
SELECT u.name, o.total
FROM users u
JOIN orders o ON u.id = o.user_id;

Keyboard Shortcuts

ActionShortcut
Execute queryCmd+Enter
Explain queryOption+Cmd+E
Select allCmd+A
CutCmd+X
CopyCmd+C
PasteCmd+V
UndoCmd+Z
RedoCmd+Shift+Z
FindCmd+F
Find and ReplaceCmd+Option+F

Best Practices

Always Use LIMIT

When exploring data, always use LIMIT to avoid loading millions of rows:
SELECT * FROM large_table LIMIT 100;

Test DELETE/UPDATE with SELECT First

Before running destructive queries, verify with SELECT:
-- First, verify what will be affected
SELECT * FROM users WHERE last_login < '2023-01-01';

-- Then run the actual delete
DELETE FROM users WHERE last_login < '2023-01-01';

Use Transactions for Safety

Wrap dangerous operations in transactions:
BEGIN;

DELETE FROM important_table WHERE condition;

-- Verify the results
SELECT COUNT(*) FROM important_table;

-- If correct:
COMMIT;

-- If wrong:
ROLLBACK;

Next Steps