|
This list of Microsoft® (MS) Access® and T-SQL® Reserved and
delimited words has extracted from Microsoft.com and is provided here as a quick
reference. MS Access and MS SQLserver are the most frequently used databases in
ColdFusion applications. In the future we will add reserved words from other
database systems.
The use of a Reserved Word in a SQL Query as a variable can
cause ODBC and other unexpected ColdFusion and application errors.
The following list includes all words reserved by the Microsoft Jet database
engine for use in SQL statements. The words in the list that are not in all
uppercase letters are also reserved by other applications. Consequently, the
individual Help topics for these words provide general descriptions that don't
focus on SQL usage.
Note Words followed by an asterisk (*) are reserved but currently have no
meaning in the context of a Microsoft Jet SQL statement (for example, Level and
TableID).
|
ADD
ALL
Alphanumeric
— See TEXT
ALTER
And
ANY
AS
ASC
AUTOINCREMENT
— See COUNTER
Avg
Between
BINARY
|
BIT
BOOLEAN
— See BIT
BY
BYTE
CHAR,
CHARACTER — See TEXT
COLUMN
CONSTRAINT
Count
COUNTER
CREATE
CURRENCY
|
|
DATABASE
DATE
— See DATETIME
DATETIME
DELETE
DESC
DISALLOW
DISTINCT
DISTINCTROW
DOUBLE
DROP
|
Eqv
EXISTS
FLOAT,
FLOAT8 — See DOUBLE
FLOAT4
— See SINGLE
FOREIGN
FROM
GENERAL
— See LONGBINARY
GROUP
GUID
HAVING
|
|
IEEEDOUBLE
— See DOUBLE
IEEESINGLE
— See SINGLE
IGNORE
Imp
In
IN
INDEX
INNER
INSERT
INT,
INTEGER, INTEGER4 — See LONG
INTEGER1
— See BYTE
INTEGER2
— See SHORT
|
INTO
Is
JOIN
KEY
LEFT
Level*
Like
LOGICAL,
LOGICAL1 — See BIT
LONG
LONGBINARY
LONGTEXT
|
|
Max
MEMO
— See LONGTEXT
Min
Mod
MONEY
— See CURRENCY
Not
NULL
NUMBER
— See DOUBLE
NUMERIC
— See DOUBLE
OLEOBJECT
— See LONGBINARY
<0o8e.htm">On
<5dbi.htm">OPTION
|
Or
ORDER
Outer*
OWNERACCESS
PARAMETERS
PERCENT
PIVOT
PRIMARY
PROCEDURE
REAL
— See SINGLE
REFERENCES
RIGHT
|
|
SELECT
SET
SHORT
SINGLE
SMALLINT
— See SHORT
SOME
StDev
StDevP
STRING
— See TEXT
Sum
TABLE
TableID*
TEXT
TIME
— See DATETIME
TIMESTAMP
— See DATETIME
|
TOP
TRANSFORM
UNION
UNIQUE
UPDATE
VALUE
VALUES
Var
VARBINARY
— See BINARY
VARCHAR
— See TEXT
VarP
WHERE
WITH
Xor
YESNO
— See BIT
|
Microsoft® SQL Server™ uses reserved keywords for defining,
manipulating, or accessing databases. Reserved keywords are part of the grammar
of the Transact-SQL language used by SQL Server to parse and understand
Transact-SQL statements and batches. Although it is syntactically possible to
use SQL Server reserved keywords as identifiers and object names in Transact-SQL
scripts, this can be done only by using delimited identifiers.
The SQL Server reserved keywords are:
|
ADD
|
EXIT
|
PRIMARY
|
|
ALL
|
FETCH
|
PRINT
|
|
ALTER
|
FILE
|
PRIVILEGES
|
|
AND
|
FILLFACTOR
|
PROC
|
|
ANY
|
FLOPPY
|
PROCEDURE
|
|
AS
|
FOR
|
PROCESSEXIT
|
|
ASC
|
FOREIGN
|
PUBLIC
|
|
AUTHORIZATION
|
FREETEXT
|
RAISERROR
|
|
AVG
|
FREETEXTTABLE
|
READ
|
|
BACKUP
|
FROM
|
READTEXT
|
|
BEGIN
|
FULL
|
RECONFIGURE
|
|
BETWEEN
|
GOTO
|
REFERENCES
|
|
BREAK
|
GRANT
|
REPEATABLE
|
|
BROWSE
|
GROUP
|
REPLICATION
|
|
BULK
|
HAVING
|
RESTORE
|
|
BY
|
HOLDLOCK
|
RESTRICT
|
|
CASCADE
|
IDENTITY
|
RETURN
|
|
CASE
|
IDENTITY_INSERT
|
REVOKE
|
|
CHECK
|
IDENTITYCOL
|
RIGHT
|
|
CHECKPOINT
|
IF
|
ROLLBACK
|
|
CLOSE
|
IN
|
ROWCOUNT
|
|
CLUSTERED
|
INDEX
|
ROWGUIDCOL
|
|
COALESCE
|
INNER
|
RULE
|
|
COLUMN
|
INSERT
|
SAVE
|
|
COMMIT
|
INTERSECT
|
SCHEMA
|
|
COMMITTED
|
INTO
|
SELECT
|
|
COMPUTE
|
IS
|
SERIALIZABLE
|
|
CONFIRM
|
ISOLATION
|
SESSION_USER
|
|
CONSTRAINT
|
JOIN
|
SET
|
|
CONTAINS
|
KEY
|
SETUSER
|
|
CONTAINSTABLE
|
KILL
|
SHUTDOWN
|
|
CONTINUE
|
LEFT
|
SOME
|
|
CONTROLROW
|
LEVEL
|
STATISTICS
|
|
CONVERT
|
LIKE
|
SUM
|
|
COUNT
|
LINENO
|
SYSTEM_USER
|
|
CREATE
|
LOAD
|
TABLE
|
|
CROSS
|
MAX
|
TAPE
|
|
CURRENT
|
MIN
|
TEMP
|
|
CURRENT_DATE
|
MIRROREXIT
|
TEMPORARY
|
|
CURRENT_TIME
|
NATIONAL
|
TEXTSIZE
|
|
CURRENT_TIMESTAMP
|
NOCHECK
|
THEN
|
|
CURRENT_USER
|
NONCLUSTERED
|
TO
|
|
CURSOR
|
NOT
|
TOP
|
|
DATABASE
|
NULL
|
TRAN
|
|
DBCC
|
NULLIF
|
TRANSACTION
|
|
DEALLOCATE
|
OF
|
TRIGGER
|
|
DECLARE
|
OFF
|
TRUNCATE
|
|
DEFAULT
|
OFFSETS
|
TSEQUAL
|
|
DELETE
|
ON
|
UNCOMMITTED
|
|
DENY
|
ONCE
|
UNION
|
|
DESC
|
ONLY
|
UNIQUE
|
|
DISK
|
OPEN
|
UPDATE
|
|
DISTINCT
|
OPENDATASOURCE
|
UPDATETEXT
|
|
DISTRIBUTED
|
OPENQUERY
|
USE
|
|
DOUBLE
|
OPENROWSET
|
USER
|
|
DROP
|
OPTION
|
VALUES
|
|
DUMMY
|
OR
|
VARYING
|
|
DUMP
|
ORDER
|
VIEW
|
|
ELSE
|
OUTER
|
WAITFOR
|
|
END
|
OVER
|
WHEN
|
|
ERRLVL
|
PERCENT
|
WHERE
|
|
ERROREXIT
|
PERM
|
WHILE
|
|
ESCAPE
|
PERMANENT
|
WITH
|
|
EXCEPT
|
PIPE
|
WORK
|
|
EXEC
|
PLAN
|
WRITETEXT
|
|
EXECUTE
|
PRECISION
|
|
|
EXISTS
|
PREPARE
|
In addition, the SQL-92 standard defines a list of reserved
keywords. It is recommended that you avoid using SQL-92 reserved keywords for
object names and identifiers. The ODBC reserved keyword list (shown below) is
the same as the SQL-92 reserved keyword list.
Note The SQL-92 reserved
keywords list sometimes can be more restrictive than SQL Server and at other
times less restrictive. For example, the SQL-92 reserved keywords list contains
INT, which SQL Server does not need to distinguish as a reserved keyword.
Transact-SQL reserved keywords can be used as identifiers or
names of databases or database objects, such as tables, columns, views, and so
on. Use either quoted identifiers or delimited identifiers. The use of reserved
keywords as the names of variables and stored procedure parameters is not
restricted. For more information, see Using
Identifiers.
ODBC Reserved Keywords
The following words are reserved for use in ODBC function calls.
These words do not constrain the minimum SQL grammar; however, to ensure
compatibility with drivers that support the core SQL grammar, applications
should avoid using these keywords.
This is the current list of ODBC reserved keywords. For more
information, see Microsoft ODBC 3.0 Programmer’s Reference, Volume
2, Appendix C.
|
ABSOLUTE
|
EXEC
|
OVERLAPS
|
|
ACTION
|
EXECUTE
|
PAD
|
|
ADA
|
EXISTS
|
PARTIAL
|
|
ADD
|
EXTERNAL
|
PASCAL
|
|
ALL
|
EXTRACT
|
POSITION
|
|
ALLOCATE
|
FALSE
|
PRECISION
|
|
ALTER
|
FETCH
|
PREPARE
|
|
AND
|
FIRST
|
PRESERVE
|
|
ANY
|
FLOAT
|
PRIMARY
|
|
ARE
|
FOR
|
PRIOR
|
|
AS
|
FOREIGN
|
PRIVILEGES
|
|
ASC
|
FORTRAN
|
PROCEDURE
|
|
ASSERTION
|
FOUND
|
PUBLIC
|
|
AT
|
FROM
|
READ
|
|
AUTHORIZATION
|
FULL
|
REAL
|
|
AVG
|
GET
|
REFERENCES
|
|
BEGIN
|
GLOBAL
|
RELATIVE
|
|
BETWEEN
|
GO
|
RESTRICT
|
|
BIT
|
GOTO
|
REVOKE
|
|
BIT_LENGTH
|
GRANT
|
RIGHT
|
|
BOTH
|
GROUP
|
ROLLBACK
|
|
BY
|
HAVING
|
ROWS
|
|
CASCADE
|
HOUR
|
SCHEMA
|
|
CASCADED
|
IDENTITY
|
SCROLL
|
|
CASE
|
IMMEDIATE
|
SECOND
|
|
CAST
|
IN
|
SECTION
|
|
CATALOG
|
INCLUDE
|
SELECT
|
|
CHAR
|
INDEX
|
SESSION
|
|
CHAR_LENGTH
|
INDICATOR
|
SESSION_USER
|
|
CHARACTER
|
INITIALLY
|
SET
|
|
CHARACTER_LENGTH
|
INNER
|
SIZE
|
|
CHECK
|
INPUT
|
SMALLINT
|
|
CLOSE
|
INSENSITIVE
|
SOME
|
|
COALESCE
|
INSERT
|
SPACE
|
|
COLLATE
|
INT
|
SQL
|
|
COLLATION
|
INTEGER
|
SQLCA
|
|
COLUMN
|
INTERSECT
|
SQLCODE
|
|
COMMIT
|
INTERVAL
|
SQLERROR
|
|
CONNECT
|
INTO
|
SQLSTATE
|
|
CONNECTION
|
IS
|
SQLWARNING
|
|
CONSTRAINT
|
ISOLATION
|
SUBSTRING
|
|
CONSTRAINTS
|
JOIN
|
SUM
|
|
CONTINUE
|
KEY
|
SYSTEM_USER
|
|
CONVERT
|
LANGUAGE
|
TABLE
|
|
CORRESPONDING
|
LAST
|
TEMPORARY
|
|
COUNT
|
LEADING
|
THEN
|
|
CREATE
|
LEFT
|
TIME
|
|
CROSS
|
LEVEL
|
TIMESTAMP
|
|
CURRENT
|
LIKE
|
TIMEZONE_HOUR
|
|
CURRENT_DATE
|
LOCAL
|
TIMEZONE_MINUTE
|
|
CURRENT_TIME
|
LOWER
|
TO
|
|
CURRENT_TIMESTAMP
|
MATCH
|
TRAILING
|
|
CURRENT_USER
|
MAX
|
TRANSACTION
|
|
CURSOR
|
MIN
|
TRANSLATE
|
|
DATE
|
MINUTE
|
TRANSLATION
|
|
DAY
|
MODULE
|
TRIM
|
|
DEALLOCATE
|
MONTH
|
TRUE
|
|
DEC
|
NAMES
|
UNION
|
|
DECIMAL
|
NATIONAL
|
UNIQUE
|
|
DECLARE
|
NATURAL
|
UNKNOWN
|
|
DEFAULT
|
NCHAR
|
UPDATE
|
|
DEFERRABLE
|
NEXT
|
UPPER
|
|
DEFERRED
|
NO
|
USAGE
|
|
DELETE
|
NONE
|
USER
|
|
DESC
|
NOT
|
USING
|
|
DESCRIBE
|
NULL
|
VALUE
|
|
DESCRIPTOR
|
NULLIF
|
VALUES
|
|
DIAGNOSTICS
|
NUMERIC
|
VARCHAR
|
|
DISCONNECT
|
OCTET_LENGTH
|
VARYING
|
|
DISTINCT
|
OF
|
VIEW
|
|
DOMAIN
|
ON
|
WHEN
|
|
DOUBLE
|
ONLY
|
WHENEVER
|
|
DROP
|
OPEN
|
WHERE
|
|
ELSE
|
OPTION
|
WITH
|
|
END
|
OR
|
WORK
|
|
END-EXEC
|
ORDER
|
WRITE
|
|
ESCAPE
|
OUTER
|
YEAR
|
|
EXCEPT
|
OUTPUT
|
ZONE
|
|
EXCEPTION
|
|
|
See Also
|
Using Reserved Keywords
|
SET
QUOTED_IDENTIFIER
|
An identifier that complies with all the rules for the format of
identifiers can be used with or without delimiters. An identifier that does not
comply with the rules for the format of regular identifiers must always be
delimited.
Delimited identifiers are used in these situations:
-
When reserved words are used for object names or portions of
object names
It is recommended that reserved keywords not be used as
object names. Databases upgraded from earlier versions of Microsoft® SQL
Server™ may contain identifiers made of words that were not reserved in
the earlier version, but are reserved words for SQL Server version 7.0. You
can refer to the object using delimited identifiers until the name can be
changed.
-
When using characters not listed as qualified identifiers
SQL Server allows any character in the current code page to
be used in a delimited identifier; however, indiscriminate use of special
characters in an object name may make SQL statements and scripts difficult
to read and maintain.
Types of delimiters used in Transact-SQL:
-
Quoted identifiers are delimited by double quotation marks
(“):
SELECT * FROM "Blanks in Table
Name"
-
Bracketed identifiers are delimited by square brackets ([
]):
SELECT * FROM [Blanks In Table Name]
Quoted identifiers are valid only when the QUOTED_IDENTIFIER
option is set ON. By default, the Microsoft OLE DB Provider for SQL Server and
SQL Server ODBC driver set QUOTED_IDENTIFIER ON when they connect. DB-Library
does not set QUOTED_IDENTIFIER ON by default. Regardless of the interface that
is used, individual applications or users may change the setting at any time.
SQL Server provides a number of ways to specify this option. For example, in SQL
Server Enterprise Manager and SQL Server Query Analyzer, the option can be set
in a dialog box. In Transact-SQL, the option can be set at various levels using
SET QUOTED_IDENTIFIER, the quoted identifier option of sp_dboption,
or the user options option of sp_configure.
When QUOTED_IDENTIFIER is ON, SQL Server follows the SQL-92
rules for the use of double quotation marks and single quotation marks in SQL
statements:
-
Double quotation marks can be used only to delimit
identifiers. They cannot be used to delimit character strings.
To maintain compatibility with existing applications, SQL
Server is not rigorous in its enforcement of this rule. Character strings
can be enclosed in double quotation marks if the string does not exceed the
length of an identifier; however, this practice is not recommended.
-
Single quotation marks must be used to enclose character
strings. They cannot be used to delimit identifiers.
If the character string contains an embedded single
quotation mark, insert an additional single quotation mark in front of the
embedded mark:
SELECT * FROM "My Table"
WHERE "Last Name" = 'O''Brien'
When QUOTED_IDENTIFIER is OFF, SQL Server follows these rules
for the use of double and single quotation marks:
-
Quotation marks cannot be used to delimit identifiers.
Instead, use brackets as delimiters.
-
Either single or double quotation marks can be used to
enclose character strings.
If double quotation marks are used, embedded single
quotation marks do not have to be denoted by two single quotation marks:
SELECT * FROM [My Table]
WHERE [Last Name] = "O'Brien"
Bracketed delimiters can always be used, regardless of the
setting of QUOTED_IDENTIFIER.
Rules for Delimited Identifiers
The rules for the format of delimited identifiers are:
-
Delimited identifiers can contain the same number of
characters as regular identifiers (1 to 128 characters, not including the
delimiter characters). Local temporary table identifiers cannot exceed 116
characters.
-
The body of the identifier can contain any combination of
characters in the current code page except the delimiting characters
themselves. For example, delimited identifiers can contain spaces, any
characters that are valid for regular identifiers, and any of the following
characters:
|
~ (tilde)
|
- (hyphen)
|
|
! (exclamation mark)
|
{ (left curly brace)
|
|
% (percent)
|
} (right curly brace)
|
|
^ (caret)
|
‘ (apostrophe)
|
|
& (ampersand)
|
. (period)
|
|
( (left parenthesis)
|
\ (backslash)
|
|
) (right parenthesis)
|
` (accent grave)
|
These examples use quoted identifiers for table names and column
names. Both methods for specifying delimited identifiers are shown.
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE "$Employee Data"
(
"^First Name" varchar(25) NOT
NULL,
"^Last Name" varchar(25) NOT NULL,
"^Dept ID" int
)
-- INSERT statements go here.
SET QUOTED_IDENTIFER OFF
GO
CREATE TABLE [^$Employee Data]
(
[^First Name] varchar(25) NOT NULL,
[^Last Name] varchar(25) NOT NULL,
[^Dept ID] int
)
-- INSERT statements go here.
After the $Employee Data and ^$Employee Data
tables are created and data is entered, rows can be retrieved:
SET QUOTED_IDENTIFER ON
GO
SELECT *
FROM "$Employee Data"
SET QUOTED_IDENTIFIER OFF
GO
-- Or
SELECT *
FROM [^$Employee Data]
In this example, a table named table contains columns tablename,
user, select, insert, and so on. Because TABLE, SELECT,
INSERT, UPDATE, and DELETE are reserved keywords, the identifiers must be
delimited every time the objects are accessed.
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE "table"
(
tablename char(128) NOT NULL,
"USER"
char(128) NOT NULL,
"SELECT" char(128) NOT
NULL,
"INSERT" char(128) NOT
NULL,
"UPDATE" char(128) NOT
NULL,
"DELETE" char(128) NOT
NULL
)
If the SET QUOTED_IDENTIFIER option is not ON, the table and
columns cannot be accessed unless bracket delimiters are used.
SET QUOTED_IDENTIFIER OFF
GO
SELECT *
FROM "table"
Here is the query result set:
Msg 170, Level 15, State 1
Line 1: Incorrect syntax near 'table'.
Here is the query using the square bracket delimiters:
SET QUOTED_IDENTIFIER OFF
GO
SELECT *
FROM [table]
Using Identifiers as Parameters in SQL Server
Many system stored procedures, functions, and DBCC statements
take object names as parameters. Some of these accept multipart object names,
while others accept only single-part names. Whether a single-part or multipart
name is expected determines how a parameter is parsed and used internally by SQL
Server.
Single-part Parameter Names
If the parameter is a single-part identifier, the name can be
specified:
-
Without quotation marks or delimiters.
-
Enclosed in single quotation marks.
-
Enclosed in double quotation marks.
-
Enclosed in brackets.
For single-part names, the string inside the single quotation
marks represents the object name. If delimiters are used inside the single
quotation marks, the delimiter characters are treated as part of the name.
If the name contains a period or other character that is not
part of the character set defined for regular identifiers, you must enclose the
object name in single quotation marks, double quotation marks, or brackets.
Multipart Parameter Names
Multipart names are qualified names that include the database or
owner name in addition to the object name. SQL Server requires that when a
multipart name is used as a parameter, the entire string that constitutes the
multipart name must be enclosed in a set of single quotation marks.
EXEC MyProcedure @name = 'dbo.Employees'
If individual name parts require delimiters, each part of the
name should be delimited separately as needed. For example, if a name part
contains a period, double quotation mark, or left or right bracket, use brackets
or double quotation marks to delimit the part. Enclose the complete name in
single quotation marks.
For example, the table name, tab.one, contains a period.
To prevent the name from being interpreted as a three part name, dbo.tab.one,
delimit the table name part.
EXEC sp_help 'dbo.[tab.one]'
This example shows the same table name delimited with double
quotation marks.
SET QUOTED_IDENTIFIER ON
GO
EXEC sp_help 'dbo."tab.one"'
GO
The table lists some of the Transact-SQL functions, DBCC
statements, and system stored procedures that use multipart names.
|
Function or stored procedure name
|
Parameter name
|
|
COL_LENGTH
|
table
|
|
DBCC CHECKIDENT
|
table_name
|
|
DBCC CHECKTABLE
|
table_name
|
|
DBCC DBREINDEX
|
database.owner.table_name
|
|
DBCC SHOW_STATISTICS
|
table
|
|
DBCC TEXTALLOC
|
table_name
|
|
DBCC UPDATEUSAGE
|
table_name
|
|
IDENT_INCR
|
table_or_view
|
|
IDENT_SEED
|
table_or_view
|
|
INDEX_COL
|
table
|
|
OBJECT_ID
|
object
|
|
sp_addextendedproc
|
procedure
|
|
sp_autostats
|
table_name
|
|
sp_bindefault
|
default
object_name
|
|
sp_bindrule
|
rule
object_name
|
|
sp_changeobjectowner
|
object
|
|
sp_depends
|
object
|
|
sp_dropextendedproc
|
procedure
|
|
sp_fulltext_column
|
qualified_table_name
|
|
sp_fulltext_table
|
qualified_table_name
|
|
sp_help
|
name
|
|
sp_helpconstraint
|
table
|
|
sp_help_fulltext_columns
|
table_name
|
|
sp_help_fulltext_columns_cursor
|
table_name
|
|
sp_help_fulltext_tables
|
table_name
|
|
sp_help_fulltext_tables_cursor
|
table_name
|
|
sp_helpindex
|
name
|
|
sp_helprotect
|
object_statement
|
|
sp_helptext
|
name
|
|
sp_helptrigger
|
table
|
|
sp_procoption
|
procedure
|
|
sp_recompile
|
table
|
|
sp_rename
|
object_name
|
|
sp_spaceused
|
objname
|
|
sp_tableoption
|
table
|
|
sp_unbindefault
|
object_name
|
|
sp_unbindrule
|
object_name
|
See Also
|
ALTER
DATABASE
|
CREATE PROCEDURE
|
|
ALTER
PROCEDURE
|
CREATE
RULE
|
|
ALTER
TABLE
|
CREATE
TABLE
|
|
ALTER
TRIGGER
|
CREATE
TRIGGER
|
|
ALTER
VIEW
|
Reserved
Keywords
|
|
CREATE
DATABASE
|
SET
QUOTED_IDENTIFIER
|
|
CREATE
DEFAULT
|
|