Skip to content

DBMS Cheatsheet

The same operation across all five engines. Each column links to its full DBMS reference. Fingerprint the engine first — see Detection.

OperationMySQL / MariaDBPostgreSQLMSSQLOracleSQLite
Comment to end of line-- - or #-- --- --- --- -
Version@@versionversion()@@versionbanner FROM v$versionsqlite_version()
Current userCURRENT_USER()current_userSYSTEM_USERuser FROM dual— (no users)
Current databaseDATABASE()current_database()DB_NAME()SYS_CONTEXT('USERENV','DB_NAME')PRAGMA database_list
String concatenationCONCAT(a,b) 'a' 'b'a || ba + ba || ba || b
SubstringSUBSTRING(s,1,1)SUBSTRING(s FROM 1 FOR 1)SUBSTRING(s,1,1)SUBSTR(s,1,1)SUBSTR(s,1,1)
Char code of charASCII(c)ascii(c)ASCII(c) / UNICODE(c)ASCII(c)UNICODE(c)
Time delaySLEEP(5)pg_sleep(5)WAITFOR DELAY '0:0:5'DBMS_PIPE.RECEIVE_MESSAGE('a',5)— (use randomblob)
First row onlyLIMIT 1LIMIT 1TOP 1WHERE ROWNUM=1LIMIT 1
List tablesinformation_schema.tablesinformation_schema.tables / pg_tablessysobjects WHERE xtype='U'all_tablessqlite_master WHERE type='table'
List columnsinformation_schema.columnsinformation_schema.columnssyscolumns / information_schema.columnsall_tab_columns (UPPERCASE names)sqlite_master.sql / pragma_table_info
Aggregate rowsGROUP_CONCAT(c)string_agg(c,',')STRING_AGG / FOR XML PATHLISTAGG(c,',')group_concat(c)
SELECT without tableSELECT 1SELECT 1SELECT 1SELECT 1 FROM dualSELECT 1
Stacked queriesRarely (driver-dependent)Yes (simple protocol)AlwaysNoexec() yes, prepare() no
Read a fileLOAD_FILE()pg_read_file()OPENROWSET(BULK …)UTL_FILE— (not possible)
Write a fileINTO OUTFILE / DUMPFILECOPY TO / lo_exportOLE automationUTL_FILEATTACH DATABASE
Command executionUDF / webshellCOPY TO PROGRAMxp_cmdshellJava SP / DBMS_SCHEDULER— (load_extension, disabled)
Error-based extractionextractvalue / updatexmlCAST to intCONVERT to intXMLType / CTXSYS— (dynamic typing)

A dash means the operation is unavailable on that engine. Escalation rows (file, command) require privileges an application account should not hold — see Defense in Depth.