Syntax: Administration
This page lists common administration tasks in five databases, so you can copy the form your database understands. Each task shows whether the SQL standard defines it (standard) or each database has its own way (dialect). For what each feature does and when to use it, follow the lesson link under each task. The SQL Syntax by Database page explains how to find out which database and version you're using.
How these were checked: every PostgreSQL and SQLite form on this page was run (PostgreSQL 18 and SQLite 3.54). MySQL, SQL Server and Oracle forms follow each database's current documentation (MySQL 8.4, SQL Server 2022 and later, Oracle AI Database 26ai); version notes such as "8.0.19+" mark features that older releases lack.
Start a Transaction
Standard. Lesson: Transactions.
| Database | Syntax |
|---|---|
| PostgreSQL | BEGIN; |
| MySQL | START TRANSACTION; |
| SQL Server | BEGIN TRANSACTION; |
| Oracle | Implicit: the first change starts one |
| SQLite | BEGIN; |
Savepoint
Standard. Lesson: Transactions.
| Database | Syntax |
|---|---|
| PostgreSQL | SAVEPOINT s; ROLLBACK TO SAVEPOINT s; |
| MySQL | SAVEPOINT s; ROLLBACK TO SAVEPOINT s; |
| SQL Server | SAVE TRANSACTION s; ROLLBACK TRANSACTION s; |
| Oracle | SAVEPOINT s; ROLLBACK TO SAVEPOINT s; |
| SQLite | SAVEPOINT s; ROLLBACK TO s; |
Set the Isolation Level
Standard. Lesson: Isolation Levels.
| Database | Syntax |
|---|---|
| PostgreSQL | SET TRANSACTION ISOLATION LEVEL SERIALIZABLE; |
| MySQL | SET TRANSACTION ISOLATION LEVEL SERIALIZABLE; |
| SQL Server | SET TRANSACTION ISOLATION LEVEL SERIALIZABLE; |
| Oracle | SET TRANSACTION ISOLATION LEVEL SERIALIZABLE; |
| SQLite | Always serializable |
Show a Query Plan
Dialect. Lesson: Reading EXPLAIN.
| Database | Syntax |
|---|---|
| PostgreSQL | EXPLAIN (ANALYZE) SELECT ...; |
| MySQL | EXPLAIN ANALYZE SELECT ...; |
| SQL Server | SET STATISTICS PROFILE ON; SELECT ...; |
| Oracle | EXPLAIN PLAN FOR SELECT ...; SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY); |
| SQLite | EXPLAIN QUERY PLAN SELECT ...; |
Create a Login
Dialect. Lesson: Users, Roles and Privileges.
| Database | Syntax |
|---|---|
| PostgreSQL | CREATE ROLE app LOGIN PASSWORD 'secret'; |
| MySQL | CREATE USER 'app'@'%' IDENTIFIED BY 'secret'; |
| SQL Server | CREATE LOGIN app WITH PASSWORD = 'secret'; CREATE USER app FOR LOGIN app; |
| Oracle | CREATE USER app IDENTIFIED BY secret; |
| SQLite | No users: access is the file's permissions |
Grant Read Access
Standard. Lesson: Users, Roles and Privileges.
| Database | Syntax |
|---|---|
| PostgreSQL | GRANT SELECT ON payments TO app; |
| MySQL | GRANT SELECT ON db.payments TO 'app'@'%'; |
| SQL Server | GRANT SELECT ON payments TO app; |
| Oracle | GRANT SELECT ON payments TO app; |
| SQLite | No privileges in SQL |
Back Up a Database
Dialect. Lesson: Backup and Restore.
| Database | Syntax |
|---|---|
| PostgreSQL | pg_dump --format=custom --file=db.dump dbname |
| MySQL | mysqldump --single-transaction dbname > db.sql |
| SQL Server | BACKUP DATABASE db TO DISK = 'C:\backup\db.bak'; |
| Oracle | expdp, or RMAN for physical backups |
| SQLite | .backup db.backup -- in the sqlite3 shell |
Parameter Placeholder in App Code
Dialect. Lesson: Parameters and Prepared Statements.
| Database | Syntax |
|---|---|
| PostgreSQL | $1, $2 (node-postgres); %s (psycopg); ? (JDBC) |
| MySQL | ? (most drivers) |
| SQL Server | @name (.NET); ? (JDBC) |
| Oracle | :name (most drivers); ? (JDBC) |
| SQLite | ? or :name |
Server Version
Dialect. Lesson: Dialect Differences Cheat Sheet.
| Database | Syntax |
|---|---|
| PostgreSQL | SELECT version(); |
| MySQL | SELECT VERSION(); |
| SQL Server | SELECT @@VERSION; |
| Oracle | SELECT banner FROM v$version; |
| SQLite | SELECT sqlite_version(); |
Try the PostgreSQL Forms
These run on the Fee Tracker in Try it:
BEGIN;
UPDATE courses SET fee_usd = fee_usd + 10 WHERE course_id = 1;
SAVEPOINT before_mistake;
UPDATE courses SET fee_usd = 1.00 WHERE course_id = 1; -- a typo
ROLLBACK TO SAVEPOINT before_mistake;
COMMIT;
SELECT title, fee_usd FROM courses WHERE course_id = 1;BEGIN
UPDATE 1
SAVEPOINT
UPDATE 1
ROLLBACK
COMMIT
title | fee_usd
-------------+---------
Java Basics | 460.00
(1 row)Was this tutorial helpful?