Special character in database name referenced in SQL

38 Views Asked by At

I am trying to access a table via phpmyadmin using SQL. The issue I am having is that the database has a - within the name and when executing the SQL it chucks a wobbly on that giving the error

#1064 - 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 '"system_prod2024-25".course_role LIMIT 0, 25' at line 1

I have tried [], " & ' to no avail.

The basic query is:-

SELECT * FROM system_prod2024-25.course_role;

Really appreciate your help on this.. The query is more complex but just need to highlight the table name. It has to be fully qualified.

Tried enclosing the table name with [], " & ' characters

1

There are 1 best solutions below

1
Kastet6398 On

In MySQL, you should escape the table name using backticks. Here's the code:

SELECT * FROM `system_prod2024-25`.`course_role`;