简体   繁体   English

在MySQL中使用auto_increment字段插入查询

[英]Insert query in mysql with an auto_increment field

Ok, 好,

I am sure I am doing something wrong here but I can't for the life of me figure it out. 我确定我在这里做错了什么,但我无法终生解决。

Here is my table 这是我的桌子

CREATE TABLE `email_queue` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `from` varchar(256) DEFAULT NULL,
  `to` varchar(4182) DEFAULT NULL,
  `cc` varchar(4182) DEFAULT NULL,
  `subject` varchar(4182) DEFAULT NULL,
  `body` varchar(4182) DEFAULT NULL,
  `status` varchar(64) DEFAULT NULL,
  `attempts` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `id_UNIQUE` (`id`)
) 

When I do a 当我做一个

insert into email_queue values (1,'','','','','','',0);

it works fine and inserts the blank values 它工作正常并插入空白值

but when I try to insert partial values using 但是当我尝试使用

insert into email_queue(to) values('sample_to_name');

it errors out saying ERROR 1064 (42000): You have an error in your SQL syntax; 它错误地指出ERROR 1064(42000):您的SQL语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near 'to) v alues('sample_to_name')' at line 1 检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在第1行的'to)v alues('sample_to_name')'附近使用

What am I doing wrong? 我究竟做错了什么?

to is mysql reserved word should be in backticks. to是mysql 保留字,应放在反引号中。

Either avoid the creating column names with Reserved words or enclose them with backtick `` 避免使用保留字创建列名或使用反引号``

insert into email_queue(`to`) values('sample_to_name');

您需要回拨

insert into email_queue(`to`) values('sample_to_name');

问题是因为

   to is mysql reserved word

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM