简体   繁体   English

代码 sql 行命令错误中的 Mysql 错误语法

[英]Mysql error syntax from code sql line command error

mysql> CREATE TABLE Poster (
->   id smallint(6) unsigned NOT NULL AUTO_INCREMENT,
->   titre VARCHAR(200) NOT NULL,
->   description text NOT NULL,
->   image_link text NOT NULL,
->   nb_commentaires int unsigned,
->   nb_likes int unsigned,
->   user_id smallint(6) DEFAULT NOT NULL,
->   date_cree timestamp,
->   PRIMARY KEY (id) NOT NULL,
-> ) ENGINE=InnoDB;

ERROR 1064 (42000): You have an error in your SQL syntax;错误 1064 (42000):您的 SQL 语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NOT NULL, date_cree timestamp, PRIMARY KEY (id) NOT NULL, ) ENGINE=InnoDB' at line 8 mysql>检查与您的 MySQL 服务器版本相对应的手册,以获取正确的语法,以便在 'NOT NULL、date_cree 时间戳、主键 (id) NOT Z6C3E226B4D4795D518AB341B0824EC2 行,第 9 行 mysql)'附近使用正确的语法

If you define a default value then do it after allowing NULL or not如果您定义一个default值,那么在允许NULL之后执行它

user_id smallint(6) NOT NULL DEFAULT 0

Also change this也改变这个

PRIMARY KEY (id) NOT NULL,

to that到那个

PRIMARY KEY (id)

complete statement:完整的声明:

 CREATE TABLE Poster 
 (
    id smallint(6) unsigned NOT NULL AUTO_INCREMENT,
    titre VARCHAR(200) NOT NULL,
    description text NOT NULL,
    image_link text NOT NULL,
    nb_commentaires int unsigned,
    nb_likes int unsigned,
    user_id smallint(6) NOT NULL DEFAULT 0,
    date_cree timestamp,
    PRIMARY KEY (id) 
 ) ENGINE=InnoDB;

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

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