Syntax: Administration

Updated · 4 min read

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.

DatabaseSyntax
PostgreSQLBEGIN;
MySQLSTART TRANSACTION;
SQL ServerBEGIN TRANSACTION;
OracleImplicit: the first change starts one
SQLiteBEGIN;

Savepoint

Standard. Lesson: Transactions.

DatabaseSyntax
PostgreSQLSAVEPOINT s; ROLLBACK TO SAVEPOINT s;
MySQLSAVEPOINT s; ROLLBACK TO SAVEPOINT s;
SQL ServerSAVE TRANSACTION s; ROLLBACK TRANSACTION s;
OracleSAVEPOINT s; ROLLBACK TO SAVEPOINT s;
SQLiteSAVEPOINT s; ROLLBACK TO s;

Set the Isolation Level

Standard. Lesson: Isolation Levels.

DatabaseSyntax
PostgreSQLSET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
MySQLSET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
SQL ServerSET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
OracleSET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
SQLiteAlways serializable

Show a Query Plan

Dialect. Lesson: Reading EXPLAIN.

DatabaseSyntax
PostgreSQLEXPLAIN (ANALYZE) SELECT ...;
MySQLEXPLAIN ANALYZE SELECT ...;
SQL ServerSET STATISTICS PROFILE ON; SELECT ...;
OracleEXPLAIN PLAN FOR SELECT ...; SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);
SQLiteEXPLAIN QUERY PLAN SELECT ...;

Create a Login

Dialect. Lesson: Users, Roles and Privileges.

DatabaseSyntax
PostgreSQLCREATE ROLE app LOGIN PASSWORD 'secret';
MySQLCREATE USER 'app'@'%' IDENTIFIED BY 'secret';
SQL ServerCREATE LOGIN app WITH PASSWORD = 'secret'; CREATE USER app FOR LOGIN app;
OracleCREATE USER app IDENTIFIED BY secret;
SQLiteNo users: access is the file's permissions

Grant Read Access

Standard. Lesson: Users, Roles and Privileges.

DatabaseSyntax
PostgreSQLGRANT SELECT ON payments TO app;
MySQLGRANT SELECT ON db.payments TO 'app'@'%';
SQL ServerGRANT SELECT ON payments TO app;
OracleGRANT SELECT ON payments TO app;
SQLiteNo privileges in SQL

Back Up a Database

Dialect. Lesson: Backup and Restore.

DatabaseSyntax
PostgreSQLpg_dump --format=custom --file=db.dump dbname
MySQLmysqldump --single-transaction dbname > db.sql
SQL ServerBACKUP DATABASE db TO DISK = 'C:\backup\db.bak';
Oracleexpdp, or RMAN for physical backups
SQLite.backup db.backup -- in the sqlite3 shell

Parameter Placeholder in App Code

Dialect. Lesson: Parameters and Prepared Statements.

DatabaseSyntax
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.

DatabaseSyntax
PostgreSQLSELECT version();
MySQLSELECT VERSION();
SQL ServerSELECT @@VERSION;
OracleSELECT banner FROM v$version;
SQLiteSELECT sqlite_version();

Try the PostgreSQL Forms

These run on the Fee Tracker in Try it:

SQL▶ 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;
Output
BEGIN
 
UPDATE 1
 
SAVEPOINT
 
UPDATE 1
 
ROLLBACK
 
COMMIT
 
    title    | fee_usd
-------------+---------
 Java Basics |  460.00
(1 row)

Was this tutorial helpful?