表未创建

时间:2014-04-12 02:54:54

标签: html mysql jsp create-table

use helpdesk;

CREATE TABLE IF NOT EXISTS `helpdesk`.`Ticket` (
  `T_ID` INT NOT NULL AUTO_INCREMENT,
  `t_date` DATETIME NULL,
  `t_equipment` VARCHAR(45) NULL,
  `t_descript` VARCHAR(300) NULL,
  PRIMARY KEY (`T_ID`),
  CONSTRAINT `emp_id`
    FOREIGN KEY ()
    REFERENCES `helpdesk`.`employee` ()
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `tech_id`
    FOREIGN KEY ()
    REFERENCES `helpdesk`.`technician` ()
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS `helpdesk`.`employee` (
  `emp_id` INT NOT NULL,
  `emp_fname` VARCHAR(45) NULL,
  `emp_lname` VARCHAR(45) NULL,
  `emp_email` VARCHAR(45) NULL,
  `emp_phone` VARCHAR(45) NULL,
  `emp_dept` VARCHAR(45) NULL,
  PRIMARY KEY (`emp_id`))
ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS `helpdesk`.`technician` (
  `tech_id` INT NOT NULL AUTO_INCREMENT,
  `tech_fname` VARCHAR(45) NOT NULL,
  `tech_lname` VARCHAR(45) NULL,
  `tech_phone` VARCHAR(45) NULL,
  `tech_email` VARCHAR(45) NULL,
  PRIMARY KEY (`tech_id`))
ENGINE = InnoDB;
INSERT INTO HELPDESK.TECHNICIAN (tech_id, tech_fname, tech_lname, tech_phone, tech_email)
VALUES(12345, SIERRA, RAY, 2485555555, SRAY@UCLA.EDU),
VALUES(12344, MICHAEL, JACKSON, 2485555554, MJACKSON@UCLA.EDU),
VALUES(12343, GREG, KEYSON, 2485555553, GKEYSON@UCLA.EDU),
VALUES(12342, AARON, BANKS, 2485555552, ABANKS@UCLA.EDU),
VALUES(12341, PHIL, COLLINS, 2485555551, PCOLLINS@UCLA.EDU);

似乎有什么问题?我的表一直给我1064错误,说有一个意外的“(”是第一个FOREIGN KEY ()语句。

2 个答案:

答案 0 :(得分:0)

试试这段代码。

CREATE TABLE IF NOT EXISTS `helpdesk`.`employee` (
  `emp_id` INT NOT NULL,
  `emp_fname` VARCHAR(45) NULL,
  `emp_lname` VARCHAR(45) NULL,
  `emp_email` VARCHAR(45) NULL,
  `emp_phone` VARCHAR(45) NULL,
  `emp_dept` VARCHAR(45) NULL,
  PRIMARY KEY (`emp_id`))
ENGINE = InnoDB;

CREATE TABLE IF NOT EXISTS `helpdesk`.`technician` (
  `tech_id` INT NOT NULL AUTO_INCREMENT,
  `tech_fname` VARCHAR(45) NOT NULL,
  `tech_lname` VARCHAR(45) NULL,
  `tech_phone` VARCHAR(45) NULL,
  `tech_email` VARCHAR(45) NULL,
  PRIMARY KEY (`tech_id`))
ENGINE = InnoDB;

CREATE TABLE IF NOT EXISTS `helpdesk`.`Ticket` (
  `T_ID` INT NOT NULL AUTO_INCREMENT,
  `t_date` DATETIME NULL,
  `t_equipment` VARCHAR(45) NULL,
  `t_descript` VARCHAR(300) NULL,
  `emp_id` INT NOT NULL,
  INDEX(`emp_id`),
  `tech_id` INT NOT NULL,
  INDEX(`tech_id`),
  PRIMARY KEY (`T_ID`),
    FOREIGN KEY (`emp_id`)
    REFERENCES `helpdesk`.`employee` (`emp_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
    FOREIGN KEY (`tech_id`)
    REFERENCES `helpdesk`.`technician` (`tech_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

答案 1 :(得分:0)

CONSTRAINT FOREIGN KEY (`tech_id`)

它应该解决它