简体   繁体   English

如何使用以下错误消息调试 SQL 查询

[英]How do I debug SQL query with the following error message

This is my query.这是我的查询。

CREATE TABLE `requirements` 
(
    `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, 
    `requirement_id` VARCHAR NOT NULL, 
    `state` VARCHAR NOT NULL, 
    `city` VARCHAR NOT NULL,
    `salary_per_anum` FLOAT NOT NULL, 
    `is_closed` TINYINT(1) NOT NULL, 
    `created_updated` DATETIME NOT NULL, 
    CONSTRAINT `pk_requirements` PRIMARY KEY(`id`)
);

and this is the error message这是错误信息

ERROR 1064 (42000): You have an error in your SQL syntax; ERROR 1064 (42000):您的 SQL 语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NOT NULL, `state` VARCHAR NOT NULL, `city` VARCHAR NOT NULL, `salary_per_anum` F' at line 1检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的“NOT NULL、`state` VARCHAR NOT NULL、`city` VARCHAR NOT NULL、`salary_per_anum` F”附近使用正确的语法

how can I debug what seems to be the issue?我如何调试似乎是问题的地方?

You need to define a length of the string colum like您需要定义字符串 colum 的长度,例如

`requirement_id` VARCHAR(100)

and the same with column state and city .与列statecity相同。

But since requirement_id looks like a number id column it must be of the same type as id in table requirements , probably int .但由于requirement_id看起来像一个数字id 列,它必须与表requirements id具有相同的类型,可能是int

Also your constraint seems to be defined wrong.此外,您的约束似乎定义错误。 It should refer to the table requirements .应参考表格requirements

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

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