![](/img/trans.png)
[英]Use current auto_increment value as basis for another field in the same INSERT query - is this possible in MySQL?
[英]Insert query in mysql with an auto_increment field
好,
我確定我在這里做錯了什么,但我無法終生解決。
這是我的桌子
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`)
)
當我做一個
insert into email_queue values (1,'','','','','','',0);
它工作正常並插入空白值
但是當我嘗試使用
insert into email_queue(to) values('sample_to_name');
它錯誤地指出ERROR 1064(42000):您的SQL語法有錯誤; 檢查與您的MySQL服務器版本相對應的手冊以獲取正確的語法,以在第1行的'to)v alues('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.