将值插入表MySQL

时间:2018-06-15 20:44:40

标签: mysql

我试图通过MySQL给出的命令提示符手动将值插入表中。与我合作的表是:

mysql> describe permissions;
+---------------------------+------------+------+-----+---------+----------------+
| Field                     | Type       | Null | Key | Default | Extra          |
+---------------------------+------------+------+-----+---------+----------------+
| id                        | int(11)    | NO   | PRI | NULL    | auto_increment |
| user_id                   | int(11)    | NO   | UNI | NULL    |                |
| admin                     | tinyint(1) | NO   |     | NULL    |                |
| quote_view                | tinyint(1) | NO   |     | NULL    |                |
| quote_create              | tinyint(1) | NO   |     | NULL    |                |
| quote_edit                | tinyint(1) | NO   |     | NULL    |                |
| inventory_edit            | tinyint(1) | NO   |     | NULL    |                |
| workorder_view            | tinyint(1) | NO   |     | NULL    |                |
| workorder_create          | tinyint(1) | NO   |     | NULL    |                |
| workorder_edit            | tinyint(1) | NO   |     | NULL    |                |
| reassign_wo               | tinyint(1) | NO   |     | NULL    |                |
| trucking_schedule_view    | tinyint(1) | NO   |     | NULL    |                |
| trucking_schedule_edit    | tinyint(1) | NO   |     | NULL    |                |
| production_schedule_view  | tinyint(1) | NO   |     | NULL    |                |
| production_schedule_basic | tinyint(1) | NO   |     | NULL    |                |
| production_schedule_sn    | tinyint(1) | NO   |     | NULL    |                |
| production_schedule_wip   | tinyint(1) | NO   |     | NULL    |                |
| serial_table_list_price   | tinyint(1) | NO   |     | NULL    |                |
+---------------------------+------------+------+-----+---------+----------------+

我尝试通过执行此命令向user_id = 1的用户授予权限:

mysql> INSERT INTO permissions
    -> (id, user_id, admin, quote_view, quote_create, quote_edit, inventory_edit, workorder_view, workorder_create, workorder_edit, reassign_wo, trucking_schedule_view, trucking_schedule_edit, production_schedule_view, production_schedule_basic, production_schedule_sn, production_schedule_wip, serial_table_list_price)
    -> VALUES
    -> ('1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1');

但是,我收到此错误:

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 'admin, quote_view, quote_create, quote_edit, inventory_edit, workorder_view, wor' at line 2

据我在网上看,我使用正确的语法。有什么想法吗?

1 个答案:

答案 0 :(得分:2)

根据{{​​3}},

ADMIN是除最新版本以外的所有版本中的保留字。

通常情况下,最好(并且更容易)使用`而不是尽量避免使用它们来划分表和列名。

即使你保持警惕,`也会保护你免受新关键字产生冲突的可能性。

示例:

INSERT INTO `permissions` (`id`, `user_id`, `admin`, `quote_view`, and so on...