gpt4 book ai didi

MySql 添加表时出错

转载 作者:行者123 更新时间:2023-11-29 12:45:25 25 4
gpt4 key购买 nike

这是我尝试执行的 SQL 查询,但失败并出现以下错误:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NOT NULL, passhash VARCHAR NOT NULL, permission TINYINT NOT NULL DEFAULT' at line 3:

这是查询:

DROP TABLE IF EXISTS `Maestros`;

CREATE TABLE `Maestros` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`nombre` VARCHAR NOT NULL,
`passhash` VARCHAR NOT NULL,
`permission` TINYINT NOT NULL DEFAULT 0,
`created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`modified` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`activo` TINYINT NOT NULL DEFAULT 1,
PRIMARY KEY (`id`),
KEY (`passhash`)
) COMMENT 'Tabla que contiene la informacion de los maestros';

最佳答案

varchar 应具有与其关联的长度,并且只能有一个具有默认值的 TimeStamp:

CREATE TABLE `Maestros` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`nombre` VARCHAR(255) NOT NULL,
`passhash` VARCHAR(255) NOT NULL,
`permission` TINYINT NOT NULL DEFAULT 0,
`created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`modified` TIMESTAMP,
`activo` TINYINT NOT NULL DEFAULT 1,
PRIMARY KEY (`id`),
KEY (`passhash`)
) COMMENT 'Tabla que contiene la informacion de los maestros';

Here是一个 SQL Fiddle。

关于MySql 添加表时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25517895/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com