Cheat Sheet

Task Example
What does SQL stand for? Structured Query Language
Default Port on which MySQL runs? 3306 TCP
Hello World example? SELECT "Hello World";
How to list all databases? SHOW DATABASES;
How to select a database to query against? USE DatabaseName
How to list storage engines? SHOW ENGINES;
How to display the structure of a table? DESCRIBE TableName or Explain TableName
How to list all tables in a database? SHOW TABLES;
How to list all views in a database? SHOW FULL TABLES IN <SUBSTITUTE_DATABASE_NAME> WHERE TABLE_TYPE LIKE 'VIEW';
How to display create database statement? SHOW CREATE DATABASE DBName;
How to display create table statement? DESCRIBE TableName; or, EXPLAIN TableName;
How to list available character sets? SHOW CHARACTER SET;
How to list available collations? SHOW COLLATION;
How to list variables and their values set for the running MySQL server? SHOW VARIABLES;
How to get rows from a table? SELECT * FROM TableName
How to create a table? CREATE TABLE MyTable (id INT, name VARCHAR(30));
How to create an index on a table? CREATE INDEX indexOnId ON MyTable(id);
How to create a table with a primary key? CREATE TABLE MyTable (id INT, name VARCHAR(30), PRIMARY KEY (id));
How to alter a name of a table? ALTER TABLE MyTable RENAME NotMyTable;
How to inner join two tables? SELECT * FROM TableA INNER JOIN TableB ON TableA.id = TableB.id;
How to left join two tables? SELECT * FROM TableA LEFT JOIN TableB ON TableA.id = TableB.id;
How to right join two tables? SELECT * FROM TableA RIGHT JOIN TableB ON TableA.id = TableB.id;
How to find a full outer join? SELECT * FROM TableA LEFT JOIN TableB ON TableA.id = TableB.id UNION ALL SELECT * FROM TableA RIGHT JOIN TableB ON TableA.id = TableB.id WHERE TableA.id IS NULL;

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy