mysql 在sql中创建表显示错误,在名称中的轻微更改可以更正它[重复]

3zwtqj6y  于 2023-01-29  发布在  Mysql
关注(0)|答案(2)|浏览(110)

此问题在此处已有答案

Syntax error due to using a reserved word as a table or column name in MySQL(1个答案)
2天前关闭。

  • 我是sql的新手,正在YouTube上学习netwrokchunk的教程。
  • 如果创建具有第一字段顺序的表,则会弹出错误
  • 如果使用第一个字段顺序创建同一个表,则不会显示任何错误。
mysql> show tables
    -> ;
+---------------------+
| Tables_in_nc_coffee |
+---------------------+
| coffee_table        |
| orders_table        |
+---------------------+
2 rows in set (0.00 sec)

mysql> drop table orders_table;
Query OK, 0 rows affected (0.03 sec)

mysql> show tables
    -> ;
+---------------------+
| Tables_in_nc_coffee |
+---------------------+
| coffee_table        |
+---------------------+
1 row in set (0.00 sec)

mysql> create table orders_table (
    -> order int,
    -> coffee int,
    -> customer int
    -> );
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 'order int,
coffee int,
customer int
)' at line 2
mysql> create table orders_table ( order int, coffee int, customer int );
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 'order int, coffee int, customer int )' at line 1
mysql> create table orders_table ( orders int, coffee int, customer int );
Query OK, 0 rows affected (0.03 sec)

mysql>

这是怎么回事?

ubof19bj

ubof19bj1#

ORDER保留字(SQL ORDER BY子句的一部分)。
使用保留字作为列名或表名通常是个坏主意,但如果你真的想这样做,MySQL会让你用反引号把它括起来:

create table orders_table ( `order` int, coffee int, customer int );
jmp7cifd

jmp7cifd2#

避免使用保留关键字作为列名。您可以使用其他名称,如“orders”,而不是“order”作为表列的名称。

相关问题