如何在 MYSQL 中从表名有空格的表中选择数据?
mysqlmysqli database更新于 2025/5/29 21:32:17
表名有空格时,需要在表名两边使用反引号。我们先创建一个表。
这里,我们使用了反引号 −
mysql> create table `Demo Table138` ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Price int ); Query OK, 0 rows affected (0.47 sec)
使用 insert 命令在表中插入记录 −
mysql> insert into `Demo Table138`(Price) values(450); Query OK, 1 row affected (0.18 sec) mysql> insert into `Demo Table138`(Price) values(499); Query OK, 1 row affected (0.16 sec) mysql> insert into `Demo Table138`(Price) values(199); Query OK, 1 row affected (0.17 sec) mysql> insert into `Demo Table138`(Price) values(3090); Query OK, 1 row affected (0.21 sec)
使用 select 命令显示表中的记录 −
以下是从表名中包含空格的表中选择数据的查询 −
mysql> select *from `Demo Table138`;
这将产生以下输出 −
+----+-------+ | Id | Price | +----+-------+ | 1 | 450 | | 2 | 499 | | 3 | 199 | | 4 | 3090 | +----+-------+ 4 rows in set (0.00 sec)
相关文章
有用资源
mysql 参考教程 - 该教程包含有关 mysql 的更多信息:https://www.cainiaomax.com/mysql/

