gpt4 book ai didi

html - 未创建表

转载 作者:行者123 更新时间:2023-11-30 00:23:57 25 4
gpt4 key购买 nike

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 () 语句出现意外的“(”。

最佳答案

试试这个代码。

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;

关于html - 未创建表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23025528/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com