共用方式為


保留關鍵字 (Transact-SQL)

更新: 2006 年 7 月 17 日

Microsoft SQL Server 2005 利用保留關鍵字來定義、操作和存取資料庫。保留的關鍵字是 SQL Server 用來剖析及瞭解 Transact-SQL 陳述式和批次之 Transact-SQL 語言文法的一部分。雖然在語意上可以利用 SQL Server 保留關鍵字作為 Transact-SQL 指令碼中的識別碼和物件名稱,但您只能利用分隔的識別碼來執行這個動作。

下表列出 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

INDEX

SECURITYAUDIT

COMMIT

INNER

SELECT

COMPUTE

INSERT

SESSION_USER

CONSTRAINT

INTERSECT

SET

CONTAINS

INTO

SETUSER

CONTAINSTABLE

IS

SHUTDOWN

CONTINUE

JOIN

SOME

CONVERT

KEY

STATISTICS

CREATE

KILL

SYSTEM_USER

CROSS

LEFT

TABLE

CURRENT

LIKE

TABLESAMPLE

CURRENT_DATE

LINENO

TEXTSIZE

CURRENT_TIME

LOAD

THEN

CURRENT_TIMESTAMP

NATIONAL

TO

CURRENT_USER

NOCHECK

TOP

CURSOR

NONCLUSTERED

TRAN

DATABASE

NOT

TRANSACTION

DBCC

NULL

TRIGGER

DEALLOCATE

NULLIF

TRUNCATE

DECLARE

OF

TSEQUAL

DEFAULT

OFF

UNION

DELETE

OFFSETS

UNIQUE

DENY

ON

UNPIVOT

DESC

OPEN

UPDATE

DISK

OPENDATASOURCE

UPDATETEXT

DISTINCT

OPENQUERY

USE

DISTRIBUTED

OPENROWSET

USER

DOUBLE

OPENXML

VALUES

DROP

OPTION

VARYING

DUMP

OR

VIEW

ELSE

ORDER

WAITFOR

END

OUTER

WHEN

ERRLVL

OVER

WHERE

ESCAPE

PERCENT

WHILE

EXCEPT

PIVOT

WITH

EXEC

PLAN

WRITETEXT

EXECUTE

PRECISION

另外,SQL-2003 標準也定義了一份保留關鍵字清單。請避免在物件名稱和識別碼上使用 SQL-2003 保留關鍵字。下表所顯示的 ODBC 保留關鍵字清單與 SQL-2003 保留關鍵字清單相同。

ms189822.note(zh-tw,SQL.90).gif附註:
SQL-2003 保留關鍵字清單,有時限制性大於 SQL Server,有時比較小。例如,SQL-2003 保留關鍵字清單包含 INT。SQL Server 並不需要將它視為保留關鍵字。

Transact-SQL 保留關鍵字可用來作為資料庫或資料庫物件 (如資料表、資料行、檢視等) 的識別碼或名稱。請使用附加引號的識別字或分隔的識別碼。利用保留關鍵字作為變數和預存程序參數的名稱,並不會受到限制。如需詳細資訊,請參閱<將識別碼當成物件名稱使用>。

ODBC 保留關鍵字

以下是 ODBC 函數呼叫所用的保留字。這些字並不會限制最基礎的 SQL 文法;不過,為了確保與支援核心 SQL 文法的驅動程式相容,應用程式應該避免使用這些關鍵字。

這是目前的 ODBC 保留關鍵字清單。

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

 

 

未來關鍵字

下列關鍵字可能保留給 SQL Server 實作新功能的未來版本。請考慮避免使用這些字作為識別碼。

ABSOLUTE

FREE

PRESERVE

ACTION

FULLTEXTTABLE

PRIOR

ADMIN

GENERAL

PRIVILEGES

AFTER

GET

READS

AGGREGATE

GLOBAL

REAL

ALIAS

GO

RECURSIVE

ALLOCATE

GROUPING

REF

ARE

HOST

REFERENCING

ARRAY

HOUR

RELATIVE

ASSERTION

IGNORE

RESULT

AT

IMMEDIATE

RETURNS

BEFORE

INDICATOR

ROLE

BINARY

INITIALIZE

ROLLUP

BIT

INITIALLY

ROUTINE

BLOB

INOUT

ROW

BOOLEAN

INPUT

ROWS

BOTH

INT

SAVEPOINT

BREADTH

INTEGER

SCROLL

CALL

INTERVAL

SCOPE

CASCADED

ISOLATION

SEARCH

CAST

ITERATE

SECOND

CATALOG

LANGUAGE

SECTION

CHAR

LARGE

SEQUENCE

CHARACTER

LAST

SESSION

CLASS

LATERAL

SETS

CLOB

LEADING

SIZE

COLLATION

LESS

SMALLINT

COMPLETION

LEVEL

SPACE

CONNECT

LIMIT

SPECIFIC

CONNECTION

LOCAL

SPECIFICTYPE

CONSTRAINTS

LOCALTIME

SQL

CONSTRUCTOR

LOCALTIMESTAMP

SQLEXCEPTION

CORRESPONDING

LOCATOR

SQLSTATE

CUBE

MAP

SQLWARNING

CURRENT_PATH

MATCH

START

CURRENT_ROLE

MINUTE

STATE

CYCLE

MODIFIES

STATEMENT

DATA

MODIFY

STATIC

DATE

MODULE

STRUCTURE

DAY

MONTH

TEMPORARY

DEC

NAMES

TERMINATE

DECIMAL

NATURAL

THAN

DEFERRABLE

NCHAR

TIME

DEFERRED

NCLOB

TIMESTAMP

DEPTH

NEW

TIMEZONE_HOUR

DEREF

NEXT

TIMEZONE_MINUTE

DESCRIBE

NO

TRAILING

DESCRIPTOR

NONE

TRANSLATION

DESTROY

NUMERIC

TREAT

DESTRUCTOR

OBJECT

TRUE

DETERMINISTIC

OLD

UNDER

DICTIONARY

ONLY

UNKNOWN

DIAGNOSTICS

OPERATION

UNNEST

DISCONNECT

ORDINALITY

USAGE

DOMAIN

OUT

USING

DYNAMIC

OUTPUT

VALUE

EACH

PAD

VARCHAR

END-EXEC

PARAMETER

VARIABLE

EQUALS

PARAMETERS

WHENEVER

EVERY

PARTIAL

WITHOUT

EXCEPTION

PATH

WORK

FALSE

POSTFIX

WRITE

FIRST

PREFIX

YEAR

FLOAT

PREORDER

ZONE

FOUND

PREPARE

請參閱

參考

SET QUOTED_IDENTIFIER (Transact-SQL)

其他資源

Transact-SQL 保留關鍵字

說明及資訊

取得 SQL Server 2005 協助

變更歷程記錄

版本 歷程記錄

2006 年 7 月 17 日

新增內容:
  • 在保留字清單中加入 EXTERNAL、PIVOT、REVERT、TABLESAMPLE、SECURITYAUDIT 和 UNPIVOT。