Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
插入包含字段的Mysql表时出错;从「;及;至;_Mysql_Mysqli_Mariadb - Fatal编程技术网

插入包含字段的Mysql表时出错;从「;及;至;

插入包含字段的Mysql表时出错;从「;及;至;,mysql,mysqli,mariadb,Mysql,Mysqli,Mariadb,当我试图插入Mysql中具有以下字段的表direction、from、to、message时,我得到了以下错误 您的SQL语法有错误;检查与您的MariaDB服务器版本相对应的手册,以了解使用接近“from,to,message”值('outing'、'from_NUMBER'、'to_NUMBER'、'asas')的正确语法 查询: INSERT INTO corporate.sms (direction, from, to, message) VALUES ( 'outgoing','FRO

当我试图插入Mysql中具有以下字段的表direction、from、to、message时,我得到了以下错误

您的SQL语法有错误;检查与您的MariaDB服务器版本相对应的手册,以了解使用接近“from,to,message”值('outing'、'from_NUMBER'、'to_NUMBER'、'asas')的正确语法

查询:

INSERT INTO corporate.sms (direction, from, to, message) VALUES ( 'outgoing','FROM_NUMBER','TO_NUMBER','test message');

有没有其他方法可以在不更改列名的情况下进行插入?

因为MySQL的SQL语法保留了“from”和“to”等字段名, 您需要将这些字段名用`(反引号)括起来

因此,您的SQL将是

INSERT INTO corporate.sms (direction, `from`, `to`, message) VALUES ( 'outgoing','FROM_NUMBER','TO_NUMBER','test message');

由于MySQL的SQL语法保留了“from”和“to”等字段名, 您需要将这些字段名用`(反引号)括起来

因此,您的SQL将是

INSERT INTO corporate.sms (direction, `from`, `to`, message) VALUES ( 'outgoing','FROM_NUMBER','TO_NUMBER','test message');

from
to
是SQL中的保留关键字

解决办法很简单。只需将查询中的
from
to
列封装在两个严重重音(```)之间,这是键盘中
选项卡
上方的键。这样,SQL解析器就可以用保留关键字区分列名并执行插入

查询变成:

INSERT INTO corporate.sms (direction, `from`, `to`, message) VALUES ( 'outgoing','FROM_NUMBER','TO_NUMBER','test message');

from
to
是SQL中的保留关键字

解决办法很简单。只需将查询中的
from
to
列封装在两个严重重音(```)之间,这是键盘中
选项卡
上方的键。这样,SQL解析器就可以用保留关键字区分列名并执行插入

查询变成:

INSERT INTO corporate.sms (direction, `from`, `to`, message) VALUES ( 'outgoing','FROM_NUMBER','TO_NUMBER','test message');

如果将它们用作字段名,请在关键字周围使用反勾号:插入corporate.sms(
方向
消息
)值('outing','from_NUMBER','to_NUMBER','test message');ups:您无法在此评论中看到它们,请将其用作背景标记:`如果将它们用作字段名,请在关键字周围使用背景标记:插入corporate.sms(
方向
消息
)值('outing','from_NUMBER','to_NUMBER','test message');ups:您在此评论中看不到它们,请使用此作为背景标记:`