Be aware it's not an exhaustive list. Click items with an arrow on the left to get details.
Structured Query Language (SQL)
It's the most widely used language for managing data in relational databases. The language is easy to learn, declarative, and very convenient to manipulate datasets.
SQL for what?
SQL can be helpful to execute queries, create data schemes, manipulate records, and retrieve data. It's often used along with a programming language to power applications.
It's an open-source object-relational database management system (RDBMS).
It's the most widely used relational database management system. It runs as a server, and you can use it to create databases and give their access to multiple users.
Columns vs. rows
In a database, All information is stored in tables. Each table is divided into rows and columns. Columns are specific attributes that allow for grouping data (e.g, id, first_name, last_name, age). Rows are records (e.g, 1001001, Kobe, Bryant, 37).
A view is a virtual table based on the result of an SQL query. It's a pretty convenient feature that allow you to run advanced queries in pre-sorted results.
ACID vs. BASE
ACID means "atomicity, consistency, isolation, and durability", and BASE stands for “Basically Available, soft state and eventual consistency”. Each approach has its advantages and drawbacks depending on what you want to achieve.
Multiple conditions in WHERE clauses that are all verified.
Multiple conditions in WHERE clauses where at least one condition is verified.
Compare a value to similar values using wildcard operators.
Search between max and min values.
Search if a row is in a table.
Determine if a value is in a specified list of literal values.
Negate logical operator (e.g., NOT EXISTS, NOT BETWEEN, NOT IN, and so on).
Equal or greater than.
Lower than or equal.
Not greater than.
Not lower than.
CREATE DATABASE my_database;
CREATE TABLE my_table (
ALTER TABLE my_table
ADD my_column my_column_definition;
Select data in table
Select data conditionally
SELECT my_column, other_column
WHERE my_column = some_value
AND other_column = other_value;
Insert data in table
INSERT INTO my_table (my_column, other_column)
VALUES (my_value, other_value);
Update data in table
SET my_column = my_value
WHERE other_column = other_value;
Delete data table
DELETE FROM my_table
SELECT my_column AS 'mycol'
Kill doublons in select
SELECT DISTINCT id FROM Players;
Sum values in column
SELECT SUM(salary) FROM Players;
SELECT last_name, age FROM Players
GROUP BY age ORDER BY last_name;
SELECT first_name, last_name FROM Players WHERE age <> 42;
CREATE VIEW my_view AS
SELECT id, first_name, last_name, age
Select data from a view
SELECT * FROM my_view;
DROP VIEW my_view;
A primary key is unique identifier for each records in a table. Its value cannot be NULL. It's often combined with
AUTO_INCREMENT to generate it automatically:
CREATE TABLE `Players` ( id INT PRIMARY KEY NOT NULL AUTO_INCREMENT, last_name varchar(255) NOT NULL, first_name varchar(255), age int, );
A UNIQUE constraint forces the use of different values in a column:
CREATE TABLE `Players` ( id int NOT NULL, last_name varchar(255) NOT NULL, first_name varchar(255), age int, UNIQUE (id) );
SELECT * FROM table_A INTERSECT SELECT * FROM table_B
INTERSECT allows you to get results that match the first query and the second query, and only that.
SELECT * FROM table_A UNION SELECT * FROM table_B
UNION is a basic command that allows for combining several queries and concatenate results. In the example above, you get results that match the first query or the second query, or both.
You can consolidate information from several different tables with a SQL
Join two tables where a condition is true in the two tables:
INNER JOIN table_B ON table_A.id = table_B.pid
Return all records from the table on the left even if the condition is not true in the second table:
LEFT JOIN table_B ON table_A.id = table_B.pid;
Return all records from the table on the right even if the condition is not true in the first table:
RIGHT JOIN table_B ON table_A.id = table_B.pid;
FULL JOIN and FULL OUTER JOIN
Join two tables where a condition is true at least in one table:
FULL JOIN table_B ON table_A.id = table_B.pid;
Join a table with itself. It's useful when there are hierarchical relationships between records:
SELECT child.id, child.name, parent.name
FROM People as child
LEFT OUTER JOIN People AS parent ON child.parent_id = parent.id
Join each line of a table with each line of a second table:
CROSS JOIN table_B;
Join two tables when they have at least one column with the same name:
NATURAL JOIN table_B;
Indexes are incredibly helpful to decrease execution time for SQL selects and WHERE clauses.
It's pretty much like the index at the end of a book where you can find all pages related to a specific topic.
Creating (or dropping) indexes does not affect data:
CREATE INDEX my_index ON my_table;
You can create an index on a specific column:
CREATE INDEX my_index ON my_table (my_column);
Be careful, though, indexes are not meant for small tables or frequently updated columns. Large operations involving updates and inserts can be significantly slower.