This SQL Syntax Reference page shows the syntax for each feature described in the SQL Tutorial. It provides a Quick Reference to SQL.
For a further description of SQL functionality, please click the links in the navigation area of this page.
SQL statements are represented as text.
SQL statements have keywords that must be spelled following rules. The keywords can be upper or lower case - SQL is not case sensitive. By convention and to improve readability, this tutorial spells SQL keywords in upper case.
SQL statements are independent of text lines. A single SQL statement can be placed on one text line or on multiple. In addition, multiple SQL statements can be combined on a single text line. By convention and to improve readability, this tutorial does not put more than one SQL statement on a single text line. Further, SQL statements are often broken into multiple lines.
A SQL statements may be terminated by a semi-colon or the word 'GO'. This tutorial leaves these terminators out. Please supply as needed.
Each condition tests column(s) using comparison operator(s). The following basic comparison operators are supported:
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:
Alphanumeric literals are enclosed in single quotes ('XXX').
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.
Here are some example datatypes:
SQL Datatype | Description |
integer(size) int(size) smallint(size) tinyint(size) | Integers |
decimal(size,decimals) numeric(size,decimals) | Numbers with decimals |
char(size) | Fixed length character string |
varchar(size) | Variable length character string |
date | A date in yyyymmdd format |
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.
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.
The means of achieving concatenation differs by database type. for example:
There must be one or more members of the value_list. Numeric and non-numeric values are supported.
The <like_condition> supports the following patterns:
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.
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:
The <having_condition> may include Aggregate Function(s).
Multiple columns can be included in the ORDER BY clause. The direction of the sort is controlled by:
Advertisements:
Infogoal.com is organized to help you gain mastery.
Examples may be simplified to facilitate learning.
Content is reviewed for errors but is not warranted to be 100% correct.
In order to use this site, you must read and agree to the
terms of use, privacy policy and cookie policy.
Copyright 2006-2020 by Infogoal, LLC. All Rights Reserved.