gpt4 book ai didi

mysql - 为什么我不能对此进行正向工程?

转载 作者:行者123 更新时间:2023-11-29 08:16:39 27 4
gpt4 key购买 nike

好的,这是更新。我正在使用 MySQL 工作台。这就是我在进行正向工程时所输入的内容。中途你会看到正向工程后的结果。

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,ALLOW_INVALID_DATES';

USE `mh23202` ;

-- -----------------------------------------------------
-- Table `mh23202`.`Patient`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mh23202`.`Patient` ;

CREATE TABLE IF NOT EXISTS `mh23202`.`Patient` (
`Patient Number` INT NOT NULL,
`First Name` TEXT NULL,
`Last Name` TEXT NULL,
`Date of Birth` DATE NULL,
`Phone Number` INT NULL,
`Email` TEXT NULL,
`Gender` TEXT NULL,
`Race` TEXT NULL,
`Address` TEXT NULL,
`Reason for Visit` TEXT NULL,
`Primary Doctor` TEXT NULL,
PRIMARY KEY (`Patient Number`),
CONSTRAINT `Visit Number`
FOREIGN KEY (`Patient Number`)
REFERENCES `mh23202`.`Visits` (`Visit Number`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `Physician Number`
FOREIGN KEY (`Patient Number`)
REFERENCES `mh23202`.`Physician` (`Physician Number`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mh23202`.`Visits`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mh23202`.`Visits` ;

CREATE TABLE IF NOT EXISTS `mh23202`.`Visits` (
`Visit Number` INT NOT NULL,
`Date of Visit` DATE NULL,
`Time of Visit` TIME NULL,
`Reason for Visit` TEXT NULL,
PRIMARY KEY (`Visit Number`),
CONSTRAINT `Patient Number`
FOREIGN KEY (`Visit Number`)
REFERENCES `mh23202`.`Patient` (`Patient Number`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `Physician Number`
FOREIGN KEY (`Visit Number`)
REFERENCES `mh23202`.`Physician` (`Physician Number`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mh23202`.`Physician`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mh23202`.`Physician` ;

CREATE TABLE IF NOT EXISTS `mh23202`.`Physician` (
`Physician Number` INT NOT NULL,
`Specialty` TEXT NULL,
`First name` TEXT NULL,
`Last Name` TEXT NULL,
`Date of Birth` DATE NULL,
`Phone Number` INT NULL,
`Email` TEXT NULL,
`Gender` TEXT NULL,
`Race` TEXT NULL,
`Address` TEXT NULL,
PRIMARY KEY (`Physician Number`),
CONSTRAINT `Visit Number`
FOREIGN KEY (`Physician Number`)
REFERENCES `mh23202`.`Visits` (`Visit Number`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mh23202`.`Medication`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mh23202`.`Medication` ;

CREATE TABLE IF NOT EXISTS `mh23202`.`Medication` (
`Prescription Number` INT NOT NULL,
`Prescription Name` TEXT NULL,
`Units per Day` TEXT NULL,
`Start Date` DATE NULL,
`Finish Date` DATE NULL,
PRIMARY KEY (`Prescription Number`),
CONSTRAINT `Patient Number`
FOREIGN KEY (`Prescription Number`)
REFERENCES `mh23202`.`Patient` (`Patient Number`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `Physician Number`
FOREIGN KEY (`Prescription Number`)
REFERENCES `mh23202`.`Physician` (`Physician Number`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mh23202`.`MedicalRecord`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mh23202`.`MedicalRecord` ;

CREATE TABLE IF NOT EXISTS `mh23202`.`MedicalRecord` (
`Physician Number` INT NULL,
`Date of Visit` DATE NULL,
`Time of Visit` TIME NULL,
`Reason for Visit` TEXT NULL,
`Findings` TEXT NULL,
`Notes` TEXT NULL,
`Treatment` TEXT NULL,
`Prescriptions` TEXT NULL,
`Procedures` TEXT NULL,
INDEX `Patient Number_idx` (`Physician Number` ASC),
CONSTRAINT `Patient Number`
FOREIGN KEY (`Physician Number`)
REFERENCES `mh23202`.`Patient` (`Patient Number`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mh23202`.`Nurse`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mh23202`.`Nurse` ;

CREATE TABLE IF NOT EXISTS `mh23202`.`Nurse` (
`Nurse Number` INT NOT NULL,
`First Name` TEXT NULL,
`Last Name` TEXT NULL,
`Date of Birth` DATE NULL,
`Phone Number` INT NULL,
`Email` TEXT NULL,
`Gender` TEXT NULL,
`Race` TEXT NULL,
`Address` TEXT NULL,
PRIMARY KEY (`Nurse Number`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mh23202`.`Secretary`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mh23202`.`Secretary` ;

CREATE TABLE IF NOT EXISTS `mh23202`.`Secretary` (
`Secretary Number` INT NOT NULL,
`First Name` TEXT NULL,
`Last Name` TEXT NULL,
`Date of Birth` DATE NULL,
`Phone Number` INT NULL,
`Email` TEXT NULL,
`Gender` TEXT NULL,
`Race` TEXT NULL,
`Address` TEXT NULL,
PRIMARY KEY (`Secretary Number`),
CONSTRAINT `Visit Number`
FOREIGN KEY (`Secretary Number`)
REFERENCES `mh23202`.`Visits` (`Visit Number`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mh23202`.`ChargeNurse`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mh23202`.`ChargeNurse` ;

CREATE TABLE IF NOT EXISTS `mh23202`.`ChargeNurse` (
`Charge Nurse Number` INT NOT NULL,
`First Name` TEXT NULL,
`Last Name` TEXT NULL,
`Date of Birth` DATE NULL,
`Phone Number` INT NULL,
`Email` TEXT NULL,
`Gender` TEXT NULL,
`Race` TEXT NULL,
`Address` TEXT NULL,
PRIMARY KEY (`Charge Nurse Number`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mh23202`.`Shifts`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mh23202`.`Shifts` ;

CREATE TABLE IF NOT EXISTS `mh23202`.`Shifts` (
`Shift Number` INT NOT NULL,
`Date of Shift` DATE NULL,
`Time of Shift` TIME NULL,
PRIMARY KEY (`Shift Number`),
CONSTRAINT `Secertary Number`
FOREIGN KEY (`Shift Number`)
REFERENCES `mh23202`.`Secretary` (`Secretary Number`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `Physician Number`
FOREIGN KEY (`Shift Number`)
REFERENCES `mh23202`.`Physician` (`Physician Number`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `Nurse Number`
FOREIGN KEY (`Shift Number`)
REFERENCES `mh23202`.`Nurse` (`Nurse Number`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `Charge Nurse Number`
FOREIGN KEY (`Shift Number`)
REFERENCES `mh23202`.`ChargeNurse` (`Charge Nurse Number`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;


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

这就是结果。

ERROR: Error 1005: Can't create table 'mh23202.visits' (errno: 121)

CREATE TABLE IF NOT EXISTS `mh23202`.`Visits` (

`Visit Number` INT NOT NULL,

`Date of Visit` DATE NULL,

`Time of Visit` TIME NULL,

`Reason for Visit` TEXT NULL,

PRIMARY KEY (`Visit Number`),

CONSTRAINT `Patient Number`

FOREIGN KEY (`Visit Number`)

REFERENCES `mh23202`.`Patient` (`Patient Number`)

ON DELETE NO ACTION

ON UPDATE NO ACTION,

CONSTRAINT `Physician Number`

FOREIGN KEY (`Visit Number`)

REFERENCES `mh23202`.`Physician` (`Physician Number`)

ON DELETE NO ACTION

ON UPDATE NO ACTION)

ENGINE = InnoDB



SQL script execution finished: statements: 7 succeeded, 1 failed



Fetching back view definitions in final form.

Nothing to fetch

Executing SQL script in server

ERROR: Error 1005: Can't create table 'mh23202.visits' (errno: 121)





CREATE TABLE IF NOT EXISTS `mh23202`.`Visits` (

`Visit Number` INT NOT NULL,

`Date of Visit` DATE NULL,

`Time of Visit` TIME NULL,

`Reason for Visit` TEXT NULL,

PRIMARY KEY (`Visit Number`),

CONSTRAINT `Patient Number`

FOREIGN KEY (`Visit Number`)

REFERENCES `mh23202`.`Patient` (`Patient Number`)

ON DELETE NO ACTION

ON UPDATE NO ACTION,

CONSTRAINT `Physician Number`

FOREIGN KEY (`Visit Number`)

REFERENCES `mh23202`.`Physician` (`Physician Number`)

ON DELETE NO ACTION

ON UPDATE NO ACTION)

ENGINE = InnoDB



SQL script execution finished: statements: 7 succeeded, 1 failed



Fetching back view definitions in final form.

Nothing to fetch

最佳答案

您的脚本中有很多错误。其中大多数是因为您正在使用 FOREIGN KEY 创建表,但没有指定它们。例如,在下面的引用部分的创建表语句中:

CONSTRAINT `Visit Number`
FOREIGN KEY ()
REFERENCES `mh23202`.`Visits` ()

空括号是每个表中的错误。对于外键,它应该具有表中的列名称,并且在 REFERENCES mh23202.Visits () 上,它应该具有来自的列名称那张 table 。

另外,正如评论中所说,您的脚本上只有一个创建表,其他表与第一个表重复。您使用的工具很可能无法正常工作,并尝试仅为一张表创建脚本。

编辑

编辑后,您的创建表命令的字段名称之间会出现空格。它不应该有或应该用 引用。正如您的第一个创建语句:患者编号。

关于mysql - 为什么我不能对此进行正向工程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20484739/

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