CheatSheets
Databases CheatSheet
CheatSheet
Table of Contents
Database Commands Cheatsheet
SQL (Structured Query Language)
Data Definition Language (DDL)
CREATE DATABASE
: Create a new databaseCREATE TABLE
: Create a new tableALTER TABLE
: Modify an existing table structureDROP TABLE
: Delete a tableTRUNCATE TABLE
: Remove all records from a tableCREATE INDEX
: Create an index on a tableDROP INDEX
: Drop an index from a table
Data Manipulation Language (DML)
INSERT INTO
: Insert new records into a tableSELECT
: Retrieve data from one or more tablesUPDATE
: Modify existing records in a tableDELETE FROM
: Delete records from a tableMERGE INTO
: Perform an "upsert" operation (insert or update) based on a condition
Data Control Language (DCL)
GRANT
: Give privileges to usersREVOKE
: Remove privileges from users
Data Query Language (DQL)
SELECT
: Retrieve data from one or more tablesJOIN
: Combine rows from two or more tables based on a related column
MySQL Specific Commands
SHOW DATABASES
: List available databasesUSE database_name
: Select a specific database to work withSHOW TABLES
: List tables in the current databaseDESCRIBE table_name
: Display the structure of a tableCREATE USER
: Create a new user accountGRANT PRIVILEGES
: Grant specific privileges to a userREVOKE PRIVILEGES
: Revoke specific privileges from a userSHOW INDEX FROM table_name
: Show indexes on a tableOPTIMIZE TABLE table_name
: Optimize the table for better performance
PostgreSQL Specific Commands
\l
: List available databases\c database_name
: Connect to a specific database\dt
: List tables in the current database\d table_name
: Describe the structure of a tableCREATE ROLE
: Create a new role (user)GRANT
: Grant privileges to a roleREVOKE
: Revoke privileges from a role\di
: List indexes in the current schemaVACUUM table_name
: Reclaim storage occupied by dead tuples and update statistics
MongoDB Specific Commands
show dbs
: List available databasesuse database_name
: Switch to a specific databaseshow collections
: List collections in the current databasedb.collection_name.find()
: Retrieve documents from a collectiondb.collection_name.insertOne()
: Insert a new document into a collectiondb.collection_name.updateOne()
: Update an existing document in a collectiondb.collection_name.deleteOne()
: Delete a document from a collectiondb.collection_name.createIndex()
: Create an index on a collectiondb.collection_name.dropIndex()
: Drop an index from a collection
SQLite Specific Commands
.databases
: List available databases.tables
: List tables in the current database.schema table_name
: Describe the structure of a table.mode
: Change the output mode (e.g., column, line).header on
: Turn on column headers in query results.quit
: Exit the SQLite shell.indices
: List indexes for a table.analyze
: Analyze and optimize the database