Underscore as a table name in MySQL is possible?

MySQLMySQLi Database

Yes, we can add underscore as a table name using backticks around the table name. Following is the syntax −

INSERT INTO `yourTableName` values(yourValue1,.......N);

Let us first create a table −

mysql> create table `DemoTable_1`
(
   Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   Location varchar(100)
);
Query OK, 0 rows affected (1.17 sec)

Insert some records in the table using insert command −

mysql> insert into `DemoTable_1`(Location) values('C:/myFolder/JavaFiles');
Query OK, 1 row affected (0.20 sec)
mysql> insert into `DemoTable_1`(Location) values('E:/AllJarOfJava');
Query OK, 1 row affected (0.17 sec)
mysql> insert into `DemoTable_1`(Location) values('C:/ProgramFiles');
Query OK, 1 row affected (0.17 sec)

Display all records from the table using select statement −

mysql> select *from `DemoTable_1`;

This will produce the following output −

+----+-----------------------+
| Id | Location              |
+----+-----------------------+
|  1 | C:/myFolder/JavaFiles |
|  2 | E:/AllJarOfJava       |
|  3 | C:/ProgramFiles       |
+----+-----------------------+
3 rows in set (0.00 sec)
raja
Published on 26-Sep-2019 10:34:50
Advertisements