简体   繁体   English

无法在 mariadb 中创建 varchar 列

[英]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查询中的错误 (1064):第 2 行的“varchar(400) 字符集 utf8 not null”附近的语法错误

What is wrong in this code?这段代码有什么问题?

Key is a reserved keyword in MySql (hence in MariaDB too), so to use it as an identifier you must enclose it in backticks. Key是 MySql 中的保留关键字(因此在 MariaDB 中也是如此),因此要将其用作标识符,您必须将其括在反引号中。 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.为了保持一致性,我还用反引号将 State 括States ,即使它并不是真正需要的。

An option would be to use another name for the new column, so to avoid the same problem in queries involving it afterwards.一个选项是为新列使用另一个名称,以避免在以后涉及它的查询中出现同样的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM