当您尝试使用保留字作为表或列名称时,会发生此错误。它可能由于-
情况1:每当您使用保留字作为表名时-mysql> create table insert
−> (
−> Id int
−> );
错误如下-ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'insert
(
Id int
)' at line 1
发生上述错误是因为单词“插入”是MySQL中的关键字。
情况2-每当您在MySQL中使用保留字作为列名时。mysql> create table Customers
−> (
−> Add int
−> );
错误如下-ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Add int
)' at line 3
发生上述错误是因为列名“ Add”是MySQL中的保留字。
为了避免上述错误,您需要了解MySQL的所有保留字。
一些MySQL保留字如下-Insert
Add
Is
Key
Like etc.
使用带有保留关键字的反引号可以解决此问题。
注意-您不能为表或列名使用保留关键字。但是,将它们加上反引号将被认为是正确的。
例如-create table `insert`
带有表以及列名的反引号的演示。mysql> create table `Insert`
−> (
−> `Add` int
−> );
借助反引号,您将不会出现任何错误。