
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Can we give underscore in a MySQL table name?
You cannot give underscore in table name. If you still want to create a new table with underscore, surround it using backticks, not single quotes.
However, let us first try to set quotes around a table name with underscore. Following is an example −
mysql> create table 'Demo_Table725'( ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY, ClientName varchar(100), ClientAge int, ClientCountryName varchar(100), isMarried boolean );
This will produce the following output i.e. an error since we haven’t used backtick −
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''Demo_Table725' ( ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY, ClientName v' at line 1
Now, we will fix the above and create the same table with backtick −
mysql> create table `Demo_Table725`( ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY, ClientName varchar(100), ClientAge int, ClientCountryName varchar(100), isMarried boolean ); Query OK, 0 rows affected (0.58 sec)
Insert some records in the table using insert command −
mysql> insert into `Demo_Table725`(ClientName,ClientAge,ClientCountryName,isMarried) values('John',34,'US',true); Query OK, 1 row affected (0.40 sec) mysql> insert into `Demo_Table725`(ClientName,ClientAge,ClientCountryName,isMarried) values('Chris',28,'UK',false); Query OK, 1 row affected (0.25 sec)
Display all records from the table using select statement −
mysql> select *from `Demo_Table725`;
This will produce the following output -
+----------+------------+-----------+-------------------+-----------+ | ClientId | ClientName | ClientAge | ClientCountryName | isMarried | +----------+------------+-----------+-------------------+-----------+ | 1 | John | 34 | US | 1 | | 2 | Chris | 28 | UK | 0 | +----------+------------+-----------+-------------------+-----------+ 2 rows in set (0.00 sec)
- Related Articles
- Underscore as a table name in MySQL is possible?
- Can we create a table with a space in name in MySQL?
- How can we change the name of a MySQL table?
- How can we update values in a MySQL table?
- How can we make a MySQL clone table?
- Can we use {} while creating a MySQL table?
- Can we add a column to a table from another table in MySQL?
- How can we remove a column from MySQL table?
- How can we insert data into a MySQL table?
- Can we remove a primary key from MySQL table?
- Can we perform MySQL UPDATE and change nothing in a table?
- Can we insert records in a MySQL table without auto_increment values?
- How can we create a table from an existing MySQL table in the database?
- Can we use “year” as a column came in a MySQL Table?
- How can we update any value in MySQL view as we can update the values in MySQL table?

Advertisements