So my query is
CREATE TABLE POSITION(
ID INT AUTO_INCREMENT PRIMARY KEY,
NAME CHAR(2) NOT NULL
);
and if i try to run this creation i receive
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 ‘POSITION(
But if a run the same query with POSITIONS or POSITION, it works fine.
Any idea why this happens?
I wanna know why i cant make a query with ‘CREATE TABLE POSITION’ on mysql
2
Answers
It’s because POSITION is a SQL keyword. You can’t use keywords as a any type of name such as table name
POSITION is a function that tells index of first occurence of string
https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_position
You encountered a bug in MySQL’s documentation: While
POSITION
is not shown in MySQL’s reserved words, it is listed as a reserved word in MariaDB documentation (POSITION
as an alias forLOCATE
already existed in MySQL 3 as there was no MariaDB yet).Possible solutions:
Choose another name for the table
Quote tablename in backticks:
CREATE TABLE `POSITION`( …..)