SQL Quick Reference

How do I?Command
Add columns to an existing table? ALTER TABLE
Add rows? 1. SELECT
2. Column or expression list (SELECT clause)
(Use the appropiate function in the query.)
Change rows? UPDATE
Create a data type for a column? 1. Data types
2. CREATE TABLE
Create a table? CREATE TABLE
Create a view? CREATE VIEW
Create an index? CREATE INDEX
Delete a table? DROP TABLE
Delete an index? DROP INDEX
Delete rows? DELETE rows
Drop a table? DROP TABLE
Drop an index? DROP INDEX
Grant a privilege? GRANT
Group data in a query? SELECT
(Use a GROUP BY clause.)
Insert rows using a query? SELECT INTO
Insert rows? INSERT
Join tables? Conditions
(Include a WHERE clause to relate the tables.)
Order query results? SELECT
(Use an ORDER BY clause.)
Remove a privilege? REVOKE
Remove rows? DELETE
Retrieve all columns? 1. SELECT
2. Column or Expression List (SELECT Clause)
(Type * in the SELECT clause.)
Retrieve all rows? SELECT
(Omit the WHERE clause.)
Retrieve only certain columns? 1. SELECT
2. Column or Expression List (SELECT Clause)
(Type the columns in the SELECT clause.)
Revoke a privilege? REVOKE
Select all columns? 1. SELECT
2. Column or Expression List (SELECT Clause)
(Type * in the SELECT clause.)
Select all rows? SELECT
(Omit the WHERE clause.)
Select only certain columns? 1. SELECT
2. Column or Expression List (SELECT Clause)
(Type the columns in the SELECT clause.)
Select only certain rows? 1. SELECT
2. Conditions
(Use a WHERE clause.)
Sort query results? SELECT
(Use an ORDER BY clause.)
Specify a foreign key? Integrity
(Use a FOREIGN KEY clause in an ALTER TABLE command.)
Specify a primary key?/td> Integrity
(Use a PRIMARY KEY clause in an ALTER TABLE command.)
Specify a privilege? GRANT
Specify integrity? Integrity
(Use a CHECK clause in an ALTER TABLE command.)
Update rows? UPDATE
Use a calculated field? 1. SELECT
2. Column or expression list. (SELECT Clause)
(Enter a calculation in the query.)
Use a compound condition in the query? Conditions
Use a compound condition? 1. SELECT
2. Conditions
(Use simple conditions connected by AND, OR, or NOT in a WHERE clause.)
Use a condition in a query? 1. SELECT
2. Conditions
(Use a WHERE Clause.)
Use a subquery? Subquery
Use a wildcard? 1. SELECT
2. Conditions
(Use LIKE and a wildcard in the WHERE clause.)
Use UNION operation? UNION
(Connect two SELECT commands with UNION.)