LLBrettK
LLBrettK

Reputation: 113

Inserting values into a table MySQL

I am trying to insert values into a table manually through the command prompt given by MySQL. The table I'm working with is this:

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    |                |
+---------------------------+------------+------+-----+---------+----------------+

I'm trying to give out permissions to a user with user_id = 1 by doing this command:

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');

However, I receive this error instead:

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

As far as I can tell by looking online I am using the right syntax. Any ideas?

Upvotes: 1

Views: 42

Answers (1)

Uueerdo
Uueerdo

Reputation: 15951

ADMIN is a reserved word in all but the most recent versions, according to the documentation.

Usually, it is best (and easier) to just delimit your table and column names with ` rather than try to avoid using them though.

Even if you're vigilant, the ` will protect you from the possibility of a new keyword creating a conflict.

Example:

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

Upvotes: 2

Related Questions