Set Blank spaces in column names with MySQL?


To set blank spaces in column names with MySQL, you can use the concept of backticks. Let us first create a table. Following is 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)

Following is the query to insert some records in the table using 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)

Following is the query to display all records from the table using a select statement −

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

Following is the output displaying blank space in 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)

Updated on: 30-Jul-2019

768 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements