SQL语句表名或者字段名和保留字冲突解决方法
最近开发遇到一个很奇葩的问题,简单做一下笔记
select * from Add ...
以上SQL语句会报错。
原因Add是表名,SQL语句保留字中又有Add
解决方法:
select * from [Add] ...
把与保留字相同的表名或者字段名用[ ]括起来,这样就能把SQL语句保留字区分开来。
***知识点***
顺便总结一下SQL语句的保留字
A
ADD
ALL
Alphanumeric - 参阅 TEXT
ALTER
And
ANY
AS
ASC
AUTOINCREMENT - 参阅 COUNTER
Avg
B-C
Between
BINARY
BIT
BOOLEAN - 参阅 BIT
BY
BYTE
CHAR,CHARACTER - 参阅 TEXT
COLUMN
CONSTRAINT
Count
COUNTER
CREATE
CURRENCY
D
DATABASE
DATE - 参阅 DATETIME
DATETIME
DELETE
DESC
DISALLOW
DISTINCT
DISTINCTROW
DOUBLE
DROP
BIT
LONG
LONGBINARY
LONGTEXT
Max
MEMO - 参阅 LONGTEXT
Min
Mod
MONEY - 参阅 CURRENCY
N-P
Not
NULL
NUMBER - 参阅 DOUBLE
NUMERIC - 参阅 DOUBLE
OLEOBJECT - 参阅 LONGBINARY
On
OPTION
Or
ORDER
Outer*
OWNERACCESS
PARAMETERS
PERCENT
PIVOT
PRIMARY
PROCEDURE
Q-S
REAL - 参阅 SINGLE
REFERENCES
RIGHT
SELECT
SET
SHORT
SINGLE
SMALLINT - 参阅 SHORT
SOME
StDev
StDevP
STRING - 参阅 TEXT
Sum
T-Z
TABLE
TableID*
TEXT
TIME - 参阅 DATETIME
TIMESTAMP - 参阅 DATETIME
TOP
TRANSFORM
UNION
UNIQUE
UPDATE
VALUE
VALUES
Var
VARBINARY - 参阅 BINARY
VARCHAR - 参阅 TEXT
VarP
WHERE
WITH
Xor
YESNO - 参阅 BIT
E-H
Eqv
EXISTS
FLOAT,FLOAT8 - 参阅 DOUBLE
FLOAT4 - 参阅 SINGLE
FOREIGN
FROM
GENERAL - 参阅 LONGBINARY
GROUP
GUID
HAVING
I
IEEEDOUBLE - 参阅 DOUBLE
IEEESINGLE - 参阅 SINGLE
IGNORE
Imp
In
IN
INDEX
INNER I
NSERT
INT,INTEGER,INTEGER4 - 参阅 LONG
INTEGER1 - 参阅 BYTE
INTEGER2 - 参阅 SHORT
INTO
Is
J-M
JOIN
KEY
LEFT
Level*
Like
LOGICAL,LOGICAL1 - 参阅