I am new to Database 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
CodePudding user response:
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,
CodePudding user response:
The issue may be related to your use of "number(10)". That is not a valid MariaDB datatype. See the MariaDB datatypes here: https://www.mariadbtutorial.com/mariadb-basics/mariadb-data-types/
EDIT: MariaDB also does not allow # in identifier names. See the valid identifier names here: https://mariadb.com/kb/en/identifier-names/