Home > Database > Mysql Tutorial > Can we create a table in MySQL with spaces in its name?

Can we create a table in MySQL with spaces in its name?

王林
Release: 2023-09-05 19:25:02
forward
1389 people have browsed it

Can we create a table in MySQL with spaces in its name?

When creating a table with spaces in the table name in MySQL, you must use backticks, otherwise an error will be reported.

Let's first look at what errors will occur when creating a table with spaces in the name, that is, the following "demo table" table name:

mysql> create table Demo Table
(
   Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   EmployeeFirstName varchar(20),
   EmployeeLastName varchar(20),
   EmployeeAge int,
   EmployeeSalary int,
   EmployeeAddress varchar(200)
);
ERROR 1064 (42000): You have an error in your syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near 'Table37
(
Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, EmployeeFirstName varchar(' at line 1 )
Copy after login

Let's use the concept of table name backtick marks. Eliminate errors. The query to create a table with spaces in MySQL is as follows:

mysql> create table `Demo Table37`
(
   Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   EmployeeFirstName varchar(20),
   EmployeeLastName varchar(20),
   EmployeeAge int,
   EmployeeSalary int,
   EmployeeAddress varchar(200)
);
Query OK, 0 rows affected (0.66 sec)

Copy after login

Above, we set the table name and surrounded the spaces with backticks, so no errors will occur:

`Demo Table37`
Copy after login

The above is the detailed content of Can we create a table in MySQL with spaces in its name?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template