在 MySQL 中用空白字元填充列名?


要使用 MySQL 在列名中設定空白字元,可以使用反引號的概念。我們首先建立一個表。以下為查詢 −

mysql> create table blankSpacesDemo
   -> (
   -> `Student Id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   -> `Student Full Name` varchar(100)
   -> );
Query OK, 0 rows affected (0.51 sec)

以下是使用 insert 命令向表中插入一些記錄的查詢 −

mysql> insert into blankSpacesDemo(`Student Full Name`) values('John Smith');
Query OK, 1 row affected (0.16 sec)

mysql> insert into blankSpacesDemo(`Student Full Name`) values('Carol Taylor');
Query OK, 1 row affected (0.14 sec)

mysql> insert into blankSpacesDemo(`Student Full Name`) values('David Miller');
Query OK, 1 row affected (0.15 sec)

以下是使用 select 語句從表中顯示所有記錄的查詢 −

mysql> select `Student Id`,`Student Full Name` from blankSpacesDemo;

以下是顯示列名“Student Full Name”中空白字元的輸出 −

+------------+--------------------+
| Student Id | Student Full Name  |
+------------+--------------------+
| 1          | John Smith         |
| 2          | Carol Taylor       |
| 3          | David Miller       |
+------------+--------------------+
3 rows in set (0.00 sec)

更新於: 30-7-2019

870 次瀏覽

開啟 職業生涯

學完課程後獲得認證

開始
廣告
© . All rights reserved.