我收到SQL语法错误

时间:2013-11-04 07:25:00

标签: php mysql sql utf-8

CREATE TABLE IF NOT EXISTS `contracts` (
  `contractId` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(32) CHARACTER SET utf8 NOT NULL COMMENT,
  `title` varchar(20) CHARACTER SET utf8 NOT NULL,
  `contractText` text CHARACTER SET utf8 NOT NULL,
  `date` datetime NOT NULL,
  `contractState` tinyint(1) NOT NULL COMMENT '1-Nepatvirtinta, 2- patvirtinta, 3-  panaikinta, 4- atmesta',
  PRIMARY KEY (`contractId`),
  UNIQUE KEY `title` (`title`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_lithuanian_ci AUTO_INCREMENT=15 ;



INSERT INTO `contracts` (`contractId`, `username`, `title`, `contractText`, `date`,   `contractState`) VALUES


CREATE TABLE IF NOT EXISTS `users` (
  `username` varchar(32) CHARACTER SET utf8 NOT NULL,
  `password` varchar(32) CHARACTER SET utf8 NOT NULL,
  `email` varchar(20) CHARACTER SET utf8 NOT NULL,
  `usergroup` tinyint(1) NOT NULL COMMENT,
  `name` varchar(32) CHARACTER SET utf8 NOT NULL,
  `lastname` varchar(32) CHARACTER SET utf8 NOT NULL,
  `state` tinyint(4) NOT NULL COMMENT,
 PRIMARY KEY (`username`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_lithuanian_ci;

在SQL服务器上运行此查询时,我收到以下错误:

MySQL说:文档

  

#1064 - 您的SQL语法出错;检查与您的MySQL服务器版本对应的手册,以便在'附近使用正确的语法     title varchar(20)CHARACTER SET utf8 NOT NULL,     第13行contractText文字CHAR'

为什么会这样?

4 个答案:

答案 0 :(得分:1)

您没有在username列添加评论。

`username` varchar(32) CHARACTER SET utf8 NOT NULL COMMENT  ,
        add one here---------------------------------------^

或删除COMMENT关键字

答案 1 :(得分:1)

在这一行

      `username` varchar(32) CHARACTER SET utf8 NOT NULL COMMENT 'comment',

为COMMENT或删除评论添加一些评论。以下是工作代码。

 CREATE TABLE IF NOT EXISTS `contracts` (
`contractId` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(32) CHARACTER SET utf8 NOT NULL COMMENT 'comment',
`title` varchar(20) CHARACTER SET utf8 NOT NULL,
`contractText` text CHARACTER SET utf8 NOT NULL,
`date` datetime NOT NULL,
`contractState` tinyint(1) NOT NULL COMMENT '1-Nepatvirtinta, 2- patvirtinta, 3-    
 panaikinta, 4- atmesta',
 PRIMARY KEY (`contractId`),
 UNIQUE KEY `title` (`title`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_lithuanian_ci AUTO_INCREMENT=15 ;

答案 2 :(得分:0)

只需修复您的表创建,即可添加显式注释或删除不需要的COMMENT关键字。

尝试将其修改为:

CREATE TABLE IF NOT EXISTS `contracts` (
  `contractId` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(32) CHARACTER SET utf8 NOT NULL COMMENT 'add explicit comment her',
  `title` varchar(20) CHARACTER SET utf8 NOT NULL,
  `contractText` text CHARACTER SET utf8 NOT NULL,
  `date` datetime NOT NULL,
  `contractState` tinyint(1) NOT NULL COMMENT '1-Nepatvirtinta, 2- patvirtinta, 3- panaikinta, 4- atmesta',
  PRIMARY KEY (`contractId`),
  UNIQUE KEY `title` (`title`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_lithuanian_ci AUTO_INCREMENT=15 ;

答案 3 :(得分:0)

从此行中删除comment

`username` varchar(32) CHARACTER SET utf8 NOT NULL , //COMMENT