Do underscores in a MySQL table name cause issues?


No, you won’t get any issues with underscores in a MySQL table name. You will get the issues with a dash in a MySQL table name.

Here is the demo that does not have any issue with underscore with table names −

_StudentTrackerDemo

Let us see the same while creating a table. The query to create a table is as follows −

mysql> create table _StudentTrackerDemo
   -> (
   -> StudentId int,
   -> StudentFirstName varchar(100)
   -> );
Query OK, 0 rows affected (0.75 sec)

The underscore is valid for table names but dash is not valid in some MySQL versions. Here is the table name with dash. The same gives an error −

mysql> create table Student-table
   -> (
   -> Id int,
   -> Name varchar(100)
   -> );
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 '-table
(Id int, Name varchar(100) )' at line 1

Updated on: 30-Jul-2019

654 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements