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.
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
What Gets Suggested
| Context | Suggestions |
|---|
After SELECT | Column names, *, functions |
After FROM | Table names, schema names |
After JOIN | Table names |
After WHERE | Column names from selected tables |
After . (dot) | Columns from the specified table |
| Start of statement | SQL 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
| Action | Shortcut | Description |
|---|
| Execute query | Cmd+Enter | Runs query at cursor, or all selected statements |
| Explain query | Option+Cmd+E | Show 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:
| Database | Syntax Used |
|---|
| MySQL / MariaDB | EXPLAIN <query> |
| PostgreSQL | EXPLAIN <query> |
| SQLite | EXPLAIN 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:
- The error message appears below the editor
- Line numbers may be highlighted if the error references a specific line
- Read the error message for details on what went wrong
Editor Settings
Customize the editor in Settings > Editor:
Font Settings
| Setting | Options | Default |
|---|
| Font Family | System Mono, SF Mono, Menlo, Monaco, Courier New | System Mono |
| Font Size | 11-18 pt | 13 pt |
Display Settings
| Setting | Description | Default |
|---|
| Show Line Numbers | Display line numbers | On |
| Highlight Current Line | Subtle highlight on cursor line | On |
| Word Wrap | Wrap long lines | Off |
Indentation Settings
| Setting | Options | Default |
|---|
| Tab Width | 2, 4, 8 spaces | 4 |
| Auto Indent | Automatic indentation | On |
Tips and Tricks
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;
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
| Action | Shortcut |
|---|
| Execute query | Cmd+Enter |
| Explain query | Option+Cmd+E |
| Select all | Cmd+A |
| Cut | Cmd+X |
| Copy | Cmd+C |
| Paste | Cmd+V |
| Undo | Cmd+Z |
| Redo | Cmd+Shift+Z |
| Find | Cmd+F |
| Find and Replace | Cmd+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