Home >Database >Mysql Tutorial >Setting spaces in column names using MySQL?

Setting spaces in column names using MySQL?

王林
王林forward
2023-09-14 23:25:06947browse

使用 MySQL 设置列名中的空格?

To set spaces in column names in MySQL, you can use the concept of backticks. Let's first create a table. The following is the statement of the query −

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)

The following is the query to insert some records in the table using the insert command-

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)

The following is the query to display all the records in the table using the select statement:

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

The following is the output showing spaces in the column name "Student Full Name" -

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

The above is the detailed content of Setting spaces in column names using MySQL?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete