简体   繁体   English

SQL错误属性(列)名称

[英]SQL bad attribute (column) names

I've created table in MySQL database with the query: 我已经使用查询在MySQL数据库中创建了表:

CREATE TABLE IF NOT EXISTS `CREW` (
`ID` INT NOT NULL,
`CALL` VARCHAR(45) NULL DEFAULT NULL,
PRIMARY KEY (`ID`));

And it did work perfectly, but when I tried to: 它确实运行良好,但是当我尝试执行以下操作时:

INSERT INTO CREW (ID, CALL) VALUES (0, 'None');

I've got ERROR 1064 . 我有ERROR 1064 What are the other bad names for attributes that we should avoid? 我们应该避免的属性的其他坏名称是什么?

You should do it like you did it in your create statement. 您应该像在create语句中那样进行操作。 Sourround the attribute names and the table names with backticks: 用反引号将属性名称和表名称包围起来:

INSERT INTO `CREW` (`ID`, `CALL`) VALUES (0, 'None');

If you do it always like this, you don't need to avoid any names. 如果您始终这样操作,则无需避免使用任何名称。

  1. It's called a column, not an attribute ;) 它称为列,而不是属性;)

  2. Don't use reserved words for column names. 列名不要使用保留字。 MySQL list here: https://dev.mysql.com/doc/refman/5.0/en/reserved-words.html . MySQL清单在这里: https : //dev.mysql.com/doc/refman/5.0/en/reserved-words.html Multi-db list here: https://www.drupal.org/node/141051 此处的多数据库列表: https : //www.drupal.org/node/141051

  3. If you want your SQL to be compatible with other databases, you should use lower snake_case 如果您希望您的SQL与其他数据库兼容,则应使用较低的snake_case

One of the column name is 'CALL' in your CREW table. 列名称之一是CREW表中的“ CALL”。 The CALL statement used to invoke a stored procedure. 用于调用存储过程的CALL语句 So when you are executing 所以当你执行

INSERT INTO CREW (ID, CALL) VALUES (0, 'None');

Mysql understand that you are some how trying to execute a stored procedure. Mysql了解您正在尝试执行存储过程。 So you need to Surround the attribute names with back-ticks 因此,您需要使用反引号将属性名称引起来

INSERT INTO CREW ('ID', 'CALL') VALUES (0, 'None');

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

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