mysql创建脚本,错误给我带来麻烦

时间:2011-10-08 16:18:19

标签: mysql database scripting

使用mySQL版本5.0.51a-24 + lenny4。以下脚本有什么问题?我一直收到以下错误:

ERROR 1064 (42000): 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 'mjla_creat.sql' at line 1

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';


-- -----------------------------------------------------
-- Table `mjla_db`.`ClassTable`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `mjla_db`.`ClassTable` (
  `classId` VARCHAR(20) NOT NULL COMMENT 'This columns is used to store the class identifier.' ,
  `className` VARCHAR(10) NOT NULL COMMENT 'Holds the name of the class. for example.' ,
  `classSection` VARCHAR(5) NOT NULL COMMENT 'Holds the section label. Used to designate which section the class is.' ,
  `classSemester` VARCHAR(2) NOT NULL COMMENT 'This is used to designate which semester. This is given two character positions incase a school needed to determine which semester within the semester.' ,
  `classYear` VARCHAR(4) NOT NULL COMMENT 'This is for the year of the class.' ,
  `teacherId` VARCHAR(20) NOT NULL ,
  PRIMARY KEY (`classId`) ,
  UNIQUE INDEX `classId_UNIQUE` (`classId` ASC) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mjla_db`.`TeacherTable`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `mjla_db`.`TeacherTable` (
  `teacherId` VARCHAR(20) NOT NULL COMMENT 'This is the teacher id. This table will have to be pre-populated by the administrator with teacher id\'s and their passwords.' ,
  `teacherPassword` VARCHAR(32) NOT NULL COMMENT 'Stores the password as md5.' ,
  PRIMARY KEY (`teacherId`) ,
  UNIQUE INDEX `teacherId_UNIQUE` (`teacherId` ASC) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mjla_db`.`QuizTable`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `mjla_db`.`QuizTable` (
  `classId` VARCHAR(20) NOT NULL COMMENT 'FK related to the ClassTable. This way each Class in the ClassTable is associated with its quiz in the QuizTable.' ,
  `quizId` INT NOT NULL AUTO_INCREMENT COMMENT 'This is the quiz number associated with the quiz.' ,
  `quizObject` BLOB NOT NULL COMMENT 'This is the actual quiz object.' ,
  `quizEnabled` TINYINT(1)  NOT NULL ,
  PRIMARY KEY (`classId`) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mjla_db`.`StudentTable`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `mjla_db`.`StudentTable` (
  `studentId` VARCHAR(20) NOT NULL ,
  `lastName` VARCHAR(45) NOT NULL ,
  `firstName` VARCHAR(45) NOT NULL ,
  `studentPassword` VARCHAR(32) NOT NULL ,
  PRIMARY KEY (`studentId`) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mjla_db`.`StudentRecordTable`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `mjla_db`.`StudentRecordTable` (
  `classId` VARCHAR(20) NOT NULL ,
  `studentId` VARCHAR(20) NOT NULL ,
  `quizGrade` TINYINT NULL ,
  `quizId` INT NOT NULL AUTO_INCREMENT ,
  PRIMARY KEY (`classId`) )
ENGINE = InnoDB;



SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;

谢谢!

1 个答案:

答案 0 :(得分:1)

  

第1行'mjla_creat.sql'附近

此字符串不会出现在您显示的SQL脚本中,因此错误不在您的SQL脚本中。这可能是您用来调用脚本的命令的错误。

您可以从shell提示符调用(您可能还需要其他选项来连接到数据库):

$ mysql mjla < mjla_creat.sql 

或者您可以从MySQL监视器调用它:

mysql> \. mjla_creat.sql

或者

mysql> source mjla_creat.sql