This code does not run:
alter table States
add Key varchar(400) character set utf8 not null
The error:
Error in query (1064): Syntax error near ‘varchar(400) character set utf8 not null’ at line 2
What is wrong in this code?
>Solution :
Key is a reserved keyword in MySql (hence in MariaDB too), so to use it as an identifier you must enclose it in backticks. This will do:
alter table `States` add `Key` varchar(400) character set utf8 not null
I’ve also enclosed States in backticks, just for the sake of consistency, even though it’s not really required.
An option would be to use another name for the new column, so to avoid the same problem in queries involving it afterwards.