插入语句损坏

时间:2019-02-09 07:33:23

标签: mysql sql insert

此插入语句有什么问题?我已经看了很多遍了,看不出有什么问题。

INSERT INTO tasks
       (task_id, priority, limit, total_active, time_limit, start_time, params)
VALUES ("d", "9", "1", "0", "1549699912", "1549696366", "");
+--------------+------------+------+-----+---------+----------------+
| Field        | Type       | Null | Key | Default | Extra          |
+--------------+------------+------+-----+---------+----------------+
| id           | int(11)    | NO   | PRI | NULL    | auto_increment |
| task_id      | varchar(2) | NO   |     | NULL    |                |
| priority     | tinyint(1) | NO   |     | 0       |                |
| limit        | int(11)    | NO   |     | NULL    |                |
| total_active | int(11)    | NO   |     | NULL    |                |
| time_limit   | int(11)    | NO   |     | NULL    |                |
| start_time   | int(11)    | NO   |     | NULL    |                |
| params       | tinytext   | YES  |     | NULL    |                |
+--------------+------------+------+-----+---------+----------------+
  

错误1064(42000):您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在第1行的'limit, total_active, time_limit, start_time, params) VALUES ("1", "d", "9", "1",'附近使用

3 个答案:

答案 0 :(得分:2)

LIMIT是sql中的关键字,您需要在其周围加上双引号。

INSERT INTO tasks(task_id, priority, "limit", total_active, time_limit, 
    start_time, params) VALUES ("d", "9", "1", "0", "1549699912", "1549696366", "");

编辑:如果这不起作用,则可以使用反引号进行转义:

INSERT INTO tasks(task_id, priority, `limit`, total_active, time_limit, 
    start_time, params) VALUES ("d", "9", "1", "0", "1549699912", "1549696366", "");

答案 1 :(得分:0)

“优先级”列默认为0。您可以在插入内容中跳过它。 试试这个。

 INSERT INTO tasks( task_id, limit, total_active, time_limit, start_time, params) VALUES 
( 'd',  1, 0, 1549699912, 1549696366, null);

谢谢

答案 2 :(得分:0)

请勿在数字中使用引号

INSERT INTO tasks(task_id, priority, `limit`, total_active, time_limit, start_time, params) 
VALUES ("d", 9, 1, 0, 1549699912, 1549696366, "");

请小心,因为问题中出现的错误消息与显示的代码不对应。

 VALUES ("1", "d", "9", 

但是在代码中您有不同的值

 VALUES ("d",  ...

并且正如Matthias Burger所建议的那样,保留字与后缀

INSERT INTO tasks(task_id, priority, `limit`, total_active, time_limit, start_time, params) 
VALUES ("d", 9, 1, 0, 1549699912, 1549696366, "");