Search code examples
sqlmariadbmysql-error-1064

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use


I am having this error. I am using MariaDB.

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'hotel_name varchar(20), city varchar(10) )' at line 3

another error

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1

create table hotel( hotel# int(10), hotel_name varchar(20), city varchar(10) );

How to solve it?


Solution

  • The # character is a comment character. Any characters following that comment until the end of the line is ignored. Read https://mariadb.com/kb/en/comment-syntax/

    So this:

    create table hotel(
      hotel# number(10),
      hotel_name varchar(10)
      ...
    

    appears to the SQL parser as:

    create table hotel(
      hotel
      hotel_name varchar(10)
      ...
    

    This is missing a data type and a comma after the column hotel.

    You can use special symbols like punctuation characters in your column names if you delimit them with back-ticks like this:

      `hotel#` int,
    

    (Also use int not number because the latter is not a data type supported by MariaDB.)

    But you would have to remember to use the back-ticks every time you reference that column in any query. It's simpler if you just avoid using special characters if you can.

    This is easier:

      hotel_num int,