-
-
Save selimslab/5e1447b0b8511fe75a92f99147c9a90f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ALTER TABLE mytable | |
ADD column DataType OptionalTableConstraint | |
DEFAULT default_value; | |
ALTER TABLE mytable | |
DROP column_to_be_deleted; | |
ALTER TABLE mytable | |
RENAME TO new_table_name; | |
DROP TABLE IF EXISTS mytable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE IF NOT EXISTS mytable ( | |
column DataType TableConstraint DEFAULT default_value, | |
another_column DataType TableConstraint DEFAULT default_value, | |
… | |
); | |
CREATE TABLE movies ( | |
id INTEGER PRIMARY KEY, | |
title TEXT, | |
director TEXT, | |
year INTEGER, | |
length_minutes INTEGER | |
); | |
INSERT INTO movies VALUES (4, "Toy Story 4", "El Directore", 2015, 90); | |
INSERT INTO boxoffice | |
(movie_id, rating, sales_in_millions) | |
VALUES (1, 9.9, 283742034 / 1000000); | |
SELECT title FROM movies | |
WHERE title LIKE "Toy Story%"; | |
SELECT rating * 10 AS rating_percent | |
WHERE column IS/IS NOT NULL | |
UPDATE movies | |
SET director = "John Lasseter" | |
WHERE id = 2; | |
DELETE FROM movies | |
where year < 2005; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
COUNT(*) | |
COUNT() | |
MIN() | |
MAX() | |
AVG() | |
SUM() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INNER JOIN = JOIN | |
LEFT JOIN | |
RIGHT JOIN | |
FULL JOIN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM | |
WHERE | |
GROUP_BY | |
HAVING | |
SELECT | |
DISTINCT | |
ORDER_BY (ASC, DESC) | |
LIMIT | |
OFFSET |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT DISTINCT column, AGG_FUNC(column_or_expression), … | |
FROM mytable | |
JOIN another_table | |
ON mytable.column = another_table.column | |
WHERE constraint_expression | |
GROUP BY column | |
HAVING constraint_expression | |
ORDER BY column ASC/DESC | |
LIMIT count OFFSET COUNT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INTEGER | |
BOOLEAN | |
TEXT | |
FLOAT | |
DOUBLE | |
CHARACTER(num_chars) | |
VARCHAR(num_chars) | |
DATE | |
DATETIME | |
BLOB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PRIMARY KEY | |
AUTOINCREMENT | |
UNIQUE | |
NOT NULL | |
CHECK (expression) | |
FOREIGN KEY |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment