SQL Notes
SQL Notes
SQL Keywords
Keyword Description
ANY Returns true if any of the subquery values meet the conditio
CREATE UNIQUE INDEX Creates a unique index on a table (no duplicate values)
CREATE VIEW Creates a view based on the result set of a SELECT stateme
DATABASE Creates or deletes an SQL database
FOREIGN KEY A constraint that is a key used to link two tables together
FULL OUTER JOIN Returns all rows when there is a match in either left table o
GROUP BY Groups the result set (used with aggregate functions: COUN
SUM, AVG)
INSERT INTO SELECT Copies data from one table into another table
LEFT JOIN Returns all rows from the left table, and the matching rows
table
NOT NULL A constraint that enforces a column to not accept NULL valu
OR Includes rows where either condition is true
OUTER JOIN Returns all rows when there is a match in either left table o
RIGHT JOIN Returns all rows from the right table, and the matching row
table
SELECT INTO Copies data from one table into a new table
SELECT TOP Specifies the number of records to return in the result set
SET Specifies which columns and values that should be updated
TRUNCATE TABLE Deletes the data inside a table, but not the table itself
UNION ALL Combines the result set of two or more SELECT statements
duplicate values)
UNIQUE A constraint that ensures that all values in a column are uni
WHERE Filters a result set to include only records that fulfill a specifi
MY SQL String Function:
INSERT Inserts a string within a string at the specified position and for a c
of characters
POW Returns the value of a number raised to the power of another num
POWER Returns the value of a number raised to the power of another num
RADIANS Converts a degree value into radians
ADDTIME Adds a time interval to a time/datetime and then returns the time
DATE_ADD Adds a time/date interval to a date and then returns the date
LAST_DAY Extracts the last day of the month for a given date
MAKEDATE Creates and returns a date based on a year and a number of day
MAKETIME Creates and returns a time based on an hour, minute, and second
QUARTER Returns the quarter of the year for a given date value
SECOND Returns the seconds part of a time/datetime
SUBDATE Subtracts a time/date interval from a date and then returns the d
SUBTIME Subtracts a time interval from a datetime and then returns the tim
YEARWEEK Returns the year and week number for a given date
CASE Goes through conditions and return a value when the first conditi
CAST Converts a value (of any type) into a specified datatype
CURRENT_USER Returns the user name and host name for the MySQL account tha
used to authenticate the current client
LAST_INSERT_ID Returns the AUTO_INCREMENT id of the last row that has been in
table
NULLIF Compares two expressions and returns NULL if they are equal. Ot
first expression is returned
SESSION_USER Returns the current MySQL user name and host name
SYSTEM_USER Returns the current MySQL user name and host name
USER Returns the current MySQL user name and host name
or
SELECT column_name
FROM table_name AS table_alias
BETWEENSELECT column_name(s)
FROM table_name
WHERE column_name
BETWEEN value1 AND value2CREATE DATABASECREATE DATABASE
database_nameCREATE TABLECREATE TABLE table_name
(
column_name1 data_type,
column_name2 data_type,
column_name3 data_type,
...
)CREATE INDEXCREATE INDEX index_name
ON table_name (column_name)
or
or
or
or
SELECT column_name(s)
INTO new_table_name [IN externaldatabase]
FROM old_table_name