我想创建一个表,但它给了我错误1046

时间:2015-01-13 05:24:43

标签: php mysql sql-server

CREATE TABLE IF NOT EXISTS `info` (
  `roll_no` integer(10) NOT NULL,
  `name` varchar(45) NULL,
  `fname` varchar(45) NULL,
  `reg_no` varchar(45) NULL,
  `cnic` varchar(45) NULL,
  `sesion` varchar(45) NULL,
  `prog` varchar(50) NULL,
  `cent` varchar(50) NULL,
  `inst` varchar(50) NULL,
  `exam` varchar(50) NULL,
  PRIMARY KEY (`roll_no`),
  ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

错误:

#1064 - 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 ') ENGINE=InnoDB DEFAULT CHARSET=latin1' at line 13

4 个答案:

答案 0 :(得分:3)

在PRIMARY KEY之后删除多余的逗号。使用此SQL查询

CREATE TABLE IF NOT EXISTS `info` (
  `roll_no` integer(10) NOT NULL,
  `name` varchar(45) NULL,
  `fname` varchar(45) NULL,
  `reg_no` varchar(45) NULL,
  `cnic` varchar(45) NULL,
  `sesion` varchar(45) NULL,
  `prog` varchar(50) NULL,
  `cent` varchar(50) NULL,
  `inst` varchar(50) NULL,
  `exam` varchar(50) NULL,
  PRIMARY KEY (`roll_no`)
  ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

希望这有助于你

答案 1 :(得分:1)

删除

末尾的逗号
PRIMARY KEY (`roll_no`),
                       ^ right there

答案 2 :(得分:1)

之后删除逗号,进行检查
  PRIMARY KEY (`roll_no`),  

然后如果存在错误,则它是旧版本..

答案 3 :(得分:0)

PRIMARY KEY ( roll_no )

之后可能是额外的逗号