SQL Basics
SQL Basics
Operator Description
= Equal
<> Not Equal
> Greater Than
< Less Than
>= Greater Than Or Equal
<= Less Than Or Equal
The comparison may involve literal value(s) that are constants like:
10
'Minnesota'
-5006.3
1
SQL ADMINISTRATION
The number of characters that can make up SQL table names and column names varies by
DBMS. In many cases the limit is 30 characters. The leading character of the name must be
alphabetic - not a number or special character. The name of a new table can not duplicate the
name of an existing table and should not be the same as a SQL reserved word. The underscore
character can be used to improve readability. The same column name can not be repeated within
a table. List elements are seperated by commas.
2
ALTER TABLE <table_name>
DROP COLUMN <column_name1> <datatype1>
The number of characters that can make up SQL names for tables, columns and indexes varies
by DBMS. In many cases the limit is 30 characters. The leading character of the name must be
alphabetic - not a number or special character. The name of a new index can not duplicate the
name of an existing index for the same table and should not be the same as a SQL reserved
word. The underscore character can be used to improve readability. List elements are seperated
by commas.
The number of characters that can make up SQL names for tables, columns and foreign keys
varies by DBMS. In many cases the limit is 30 characters. The leading character of the name
must be alphabetic - not a number or special character. The name of a new foreign key can not
duplicate the name of an existing foreign key for the database and should not be the same as a
SQL reserved word. To make the foreign key unique it is common practice to include the table
and column name as part of the foreign key name. The underscore character can be used to
improve readability. List elements are seperated by commas.
3
ALTER TABLE <table_name>
DROP FOREIGN KEY <foreignkey_name>
The number of characters that can make up SQL names for tables, columns and views varies by
DBMS. In many cases the limit is 30 characters. The leading character of the name must be
alphabetic - not a number or special character. The name of a new view can not duplicate the
name of an existing view or table and should not be the same as a SQL reserved word. The
underscore character can be used to improve readability. List elements are seperated by
commas.
SQL ADVANCED
4
SQL IN Syntax
SELECT <column_list>
FROM <table_name>
WHERE <column_name IN (value_list)>
There must be one or more members of the value_list. Numeric and non-numeric values are
supported.
The word DISTINCT can be placed in front of a single column name or a number of column
names. When in front of multiple column names, a distinct combination is returned.
5
SELECT <column_name1>, <column_name2> <aggregate_function>
FROM <table_name>
GROUP BY <column_name1>, <column_name2>
The GROUP BY clause must follow the FROM and WHERE clauses. The columns in a SELECT
clause must be either group by columns or aggregate function columns.
The SQL Aggregate Functions are functions that provide mathematical operations. The functions
include:
Multiple columns can be included in the ORDER BY clause. The direction of the sort is controlled
by:
6
FROM <table_name>
JOIN <table_name> ON <join_conditions>