... creates a database with the given name...
CREATE [OR REPLACE] DATABASE [IF NOT EXISTS] database_name; ... drop an existing database...
DROP DATABASE [IF EXISTS] database_name; Use the
database_namedatabase as the default (current) database for subsequent statements.
USE database_name... create a new table...
CREATE TABLE [OR REPLACE] table_name [IF NOT EXISTS] (
column1 datatype constraint,
column2 datatype constraint,
column3 datatype constraint,
....
);
CREATE TABLE new_table_name AS
SELECT column1, column2,...
FROM existing_table_name
WHERE ....; ... alter an existing table's definition...
ALTER TABLE table_name
ADD column_name datatype;
ALTER TABLE table_name
ALTER COLUMN column_name datatype;
ALTER TABLE table_name
DROP COLUMN column_name; ... drop an existing table...
DROP TABLE table_name [IF EXISTS]; Provides information about the columns in a table...
DESCRIBE table_name; ... add (or insert) new data...
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
INSERT INTO table_name
VALUES (value1, value2, value3, ...); ... read (or select) your data...
SELECT column1, column2, ...
FROM table_name;
SELECT * FROM table_name; ... change (or update) existing data...
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition; ... remove (or delete) existing data...
DELETE FROM table_name WHERE condition;... add or change (or replace) new or existing data...
REPLACE INTO table_name... empty (or delete) all data from the template...
TRUNCATE TABLE table_name; CASE
WHEN condition1 THEN result1
WHEN condition2 THEN result2
WHEN conditionN THEN resultN
ELSE result
END; NOT NULL: Ensures that a column cannot have aNULLvalueUNIQUE: Ensures that all values in a column are differentPRIMARY KEY: A combination of aNOT NULLandUNIQUE. Uniquely identifies each row in a tableFOREIGN KEY: Uniquely identifies a row/record in another tableCHECK: Ensures that all values in a column satisfies a specific conditionDEFAULT: Sets a default value for a column when no value is specifiedINDEX: Used to create and retrieve data from the database very quickly
LIKE:IN: eg.... WHERE column_name IN (value1, value2, ...);or... WHERE column_name IN (SELECT STATEMENT);BETWEEN: inclusive eg.... WHERE column_name BETWEEN value1 AND value2;
MINMAXCOUNTAVGSUM