YouTip LogoYouTip

Sql Quickref

* * * | SQL Statement | Syntax | Description | | --- | --- | --- | | **AND / OR** | SELECT column_name(s) FROM table_name WHERE condition AND|OR condition | AND: represents logical AND OR: represents logical OR | | **ALTER TABLE** | `ALTER TABLE table_name ADD column_name datatypeALTER TABLE table_name DROP COLUMN column_name` | Used to modify the structure of an existing table, adding or deleting columns. | | **AS (alias)** | `SELECT column_name AS column_alias FROM table_nameSELECT column_name FROM table_name AS table_alias` | Used to assign aliases to columns or tables. | | **BETWEEN** | `SELECT column_name(s) FROM table_name WHERE column_name BETWEEN value1 AND value2` | Used to filter records within a specified range. | | **CREATE DATABASE** | `CREATE DATABASE database_name` | Used to create a new database. | | **CREATE TABLE** | `CREATE TABLE table_name (column_name1 data_type, column_name2 data_type, ...)` | Used to create a new table, defining its columns and data types. | | **CREATE INDEX** | `CREATE INDEX index_name ON table_name (column_name)CREATE UNIQUE INDEX index_name ON table_name (column_name)` | Used to create indexes on table columns to speed up queries. | | **CREATE VIEW** | `CREATE VIEW view_name AS SELECT column_name(s) FROM table_name WHERE condition` | Used to create views to store the results of complex queries. | | **DELETE** | `DELETE FROM table_name WHERE some_column=some_valueDELETE FROM table_nameDELETE * FROM table_name` | Used to delete records from a table; `DELETE FROM table_name` and `DELETE * FROM table_name` will delete all records. | | **DROP DATABASE** | `DROP DATABASE database_name` | Used to delete a database. | | **DROP INDEX** | `DROP INDEX table_name.index_name (SQL Server)DROP INDEX index_name ON table_name (MS Access)DROP INDEX index_name (DB2/Oracle)ALTER TABLE table_name DROP INDEX index_name (MySQL)` | Used to delete indexes on a table. | | **DROP TABLE** | `DROP TABLE table_name` | Used to delete a table and all its data. | | **GROUP BY** | `SELECT column_name, aggregate_function(column_name) FROM table_name WHERE column_name operator value GROUP BY column_name` | Used to group the result set by one or more columns. | | **HAVING** | `SELECT column_name, aggregate_function(column_name) FROM table_name WHERE column_name operator value GROUP BY column_name HAVING aggregate_function(column_name) operator value` | Used to filter the grouped result set. | | **IN** | `SELECT column_name(s) FROM table_name WHERE column_name IN (value1, value2, ...)` | Used to filter records that match any value in a given set. | | **INSERT INTO** | `INSERT INTO table_name VALUES (value1, value2, ...)INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...)` | Used to insert new records into a table. | | **INNER JOIN** | `SELECT column_name(s) FROM table_name1 INNER JOIN table_name2 ON table_name1.column_name=table_name2.column_name` | Used to return matching records from two tables. | | **LEFT JOIN** | `SELECT column_name(s) FROM table_name1 LEFT JOIN table_name2 ON table_name1.column_name=table_name2.column_name` | Used to return all records from the left table and matching records from the right table. | | **RIGHT JOIN** | `SELECT column_name(s) FROM table_name1 RIGHT JOIN table_name2 ON table_name1.column_name=table_name2.column_name` | Used to return all records from the right table and matching records from the left table. | | **FULL JOIN** | `SELECT column_name(s) FROM table_name1 FULL JOIN table_name2 ON table_name1.column_name=table_name2.column_name` | Used to return all records from both tables, regardless of whether they match. | | **LIKE** | `SELECT column_name(s) FROM table_name WHERE column_name LIKE pattern` | Used to filter records that match a specific pattern. | | **ORDER BY** | SELECT column_name(s) FROM table_name ORDER BY column_name [ASC|DESC] | Used to sort the result set. ASC indicates ascending order (default), while DESC indicates descending order. | | **SELECT** | `SELECT column_name(s) FROM table_name` | Used to select data from a table. | | **SELECT** | `SELECT * FROM table_name` | Used to select all columns from a table. | | **SELECT DISTINCT** | `SELECT DISTINCT column_name(s) FROM table_name` | Used to return only unique values. | | **SELECT INTO** | `SELECT * INTO new_table_name FROM old_table_nameSELECT column_name(s) INTO new_table_name FROM old_table_name` | Used to select data from one table and insert it into a new table. | | **SELECT TOP** | SELECT TOP number|percent column_name(s) FROM table_name ORDER BY column_name [ASC|DESC] | Returns the top specified number of records from a table, with options for absolute count or percentage. | | **TRUNCATE TABLE** | `TRUNCATE TABLE table_name` | Used to delete all data from a table without removing the table structure. | | **UNION** | `SELECT column_name(s) FROM table_name1 UNION SELECT column_name(s) FROM table_name2` | Used to combine the result sets of two or more SELECT statements, excluding duplicate records. | | **UNION ALL** | `SELECT column_name(s) FROM table_name1 UNION ALL SELECT column_name(s) FROM table_name2` | Used to combine the result sets of two or more SELECT statements, including duplicate records. | | **UPDATE** | `UPDATE table_name SET column1=value, column2=value, ... WHERE some_column=some_value` | Used to modify existing records in a table. | | **WHERE** | `SELECT column_name(s) FROM table_name WHERE column_name operator value` | Used to filter records by specifying query conditions. |
← Sql HostingSql Func Format β†’