Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can not create varchar column in mariadb

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading