SQL 关键字

保留关键字是 SQL Server 使用的 Transact-SQL 语言语法的一部分，用于分析和理解 Transact-SQL 语句和批处理。尽管在 Transact-SQL 脚本中使用 SQL Server 保留关键字作为标识符和对象名在语法上是可行的，但规定只能使用分隔标识符。

下表列出了 SQL Server 保留关键字。

ADD | EXISTS | PRIMARY
ALL | EXIT | PRINT
ALTER | EXTERNAL | PROC
AND | FETCH | PROCEDURE
ANY | FILE | PUBLIC
AS | FILLFACTOR | RAISERROR
ASC | FOR | READ
AUTHORIZATION | FOREIGN | READTEXT
BACKUP | FREETEXT | RECONFIGURE
BEGIN | FREETEXTTABLE | REFERENCES
BETWEEN | FROM | REPLICATION
BREAK | FULL | RESTORE
BROWSE | FUNCTION | RESTRICT
BULK | GOTO | RETURN
BY | GRANT | REVERT
CASCADE | GROUP | REVOKE
CASE | HAVING | RIGHT
CHECK | HOLDLOCK | ROLLBACK
CHECKPOINT | IDENTITY | ROWCOUNT
CLOSE | IDENTITY_INSERT | ROWGUIDCOL
CLUSTERED | IDENTITYCOL | RULE
COALESCE | IF | SAVE
COLLATE | IN | SCHEMA
COLUMN | INDEXIN | SECURITYAUDIT
COMMIT | INNERINDEX | SELECT
COMPUTE | INSERTINNER | SESSION_USER
CONSTRAINT | INTERSECTINSERT | SET
CONTAINS | INTOINTERSECT | SETUSER
CONTAINSTABLE | ISINTO | SHUTDOWN
CONTINUE | JOINIS | SOME
CONVERT | KEYJOIN | STATISTICS
CREATE | KILLKEY | SYSTEM_USER
CROSS | LEFTKILL | TABLE
CURRENT | LIKELEFT | TABLESAMPLE
CURRENT_DATE | LINENOLIKE | TEXTSIZE
CURRENT_TIME | LOADLINENO | THEN
CURRENT_TIMESTAMP | NATIONAL LOAD | TO
CURRENT_USER | NOCHECKNATIONAL | TOP
CURSOR | NONCLUSTEREDNOCHECK | TRAN
DATABASE | NOTNONCLUSTERED | TRANSACTION
DBCC | NULLNOT | TRIGGER
DEALLOCATE | NULLIFNULL | TRUNCATE
DECLARE | OFNULLIF | TSEQUAL
DEFAULT | OFFOF | UNION
DELETE | OFFSETSOFF | UNIQUE
DENY | ONOFFSETS | UNPIVOT
DESC | OPENON | UPDATE
DISK | OPENDATASOURCEOPEN | UPDATETEXT
DISTINCT | OPENQUERYOPENDATASOURCE | USE
DISTRIBUTED | OPENROWSETOPENQUERY | USER
DOUBLE | OPENXMLOPENROWSET | VALUES
DROP | OPTIONOPENXML | VARYING
DUMP | OROPTION | VIEW
ELSE | ORDEROR | WAITFOR
END | OUTERORDER | WHEN
ERRLVL | OVEROUTER | WHERE
ESCAPE | PERCENTOVER | WHILE
EXCEPT | PIVOTPERCENT | WITH
EXEC | PLANPIVOT | WRITETEXT
EXECUTE | PLAN PRECISION |

另外，SQL-2003 标准还定义了保留关键字列表。不要使用 SQL-2003 保留关键字作为对象名和标识符。ODBC 保留关键字列表（如下表所示）与 SQL-2003 保留关键字列表相同。

注意：

SQL-2003 保留关键字列表有时可能比 SQL Server 限制更多，有时则限制更少。例如，SQL-2003 保留关键字列表包含 INT，而 SQL Server 不需要将其区分为保留关键字。

Transact-SQL 保留关键字可用作数据库或数据库对象（如表、列、视图等）的标识符或名称。使用带引号的标识符或分隔标识符。不限制将保留关键字用作变量和存储过程参数的名称。