createtableDemoTable( IdintNOTNULLAUTO_INCREMENTPRIMARYKEY, EmployeeFirstNamevarchar(20), EmployeeLastNamevarchar(20"/> createtableDemoTable( IdintNOTNULLAUTO_INCREMENTPRIMARYKEY, EmployeeFirstNamevarchar(20), EmployeeLastNamevarchar(20">

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

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

王林
王林forward
2023-09-05 19:25:021322browse

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 )

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)

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

`Demo Table37`

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!

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