如何ER图MYSQL

我正在尝试在mysql中创建简单的库数据库。我有5个表格的学生,条目,书籍,打字本,作者。当我尝试使用mysql逆向工程制作er图表时,我的表在er图表上没有任何关系。但是,几乎每个数据库在Internet上的关系图中都具有关系。我在做什么错以及如何解决?

CREATE TABLE student(
`stuNo` INT NOT NULL,
`stuname` VARCHAR(45) NULL,
`stusurname` VARCHAR(45) NULL,
`class` INT NULL,
`age` INT NULL,
PRIMARY KEY (`stuNo`));

 CREATE TABLE entry(
`stuNo` INT NOT NULL,
`entryno` INT NOT NULL,
`bookno` INT NOT NULL,
`borrowdate` DATE NULL,
`returndate` DATE NULL,
PRIMARY KEY (`bookno`));

 CREATE TABLE book(
`bookno` INT NOT NULL,
`bookname` VARCHAR(45) NULL,
 `authorno` INT NOT NULL,
`typeno` INT NOT NULL,
PRIMARY KEY (authorno , typeno));

 CREATE TABLE  typebook (
`typeno` INT NOT NULL,
`typename` VARCHAR(45) NULL,
PRIMARY KEY (`typeno`));

 CREATE TABLE author(
`authorno` INT NOT NULL,
`authorname` VARCHAR(45) NULL,
`autorname` VARCHAR(45) NULL,
PRIMARY KEY (`authorno`));

enter image description here

评论
满足ni
满足ni

我不得不切换CREATE TABLE的顺序

更改的是您必须插入数据的顺序。 例如

如果您想插入一本书,则首先必须插入打字本和该书对应的授权书,依此类推。

CREATE TABLE student(
`stuNo` INT NOT NULL,
`stuname` VARCHAR(45) NULL,
`stusurname` VARCHAR(45) NULL,
`class` INT NULL,
`age` INT NULL,
PRIMARY KEY (`stuNo`));

 CREATE TABLE  typebook (
`typeno` INT NOT NULL,
`typename` VARCHAR(45) NULL,
PRIMARY KEY (`typeno`));

 CREATE TABLE author(
`authorno` INT NOT NULL,
`authorname` VARCHAR(45) NULL,
`autorname` VARCHAR(45) NULL,
PRIMARY KEY (`authorno`));

CREATE TABLE book(
`bookno` INT NOT NULL,
`bookname` VARCHAR(45) NULL,
 `authorno` INT NOT NULL,
`typeno` INT NOT NULL,
PRIMARY KEY (authorno , typeno),
INDEX(bookno),
FOREIGN KEY (typeno)
        REFERENCES typebook(typeno),
FOREIGN KEY (authorno)
        REFERENCES author(authorno));

 CREATE TABLE entry(
`stuNo` INT NOT NULL,
`entryno` INT NOT NULL,
`bookno` INT NOT NULL,
`borrowdate` DATE NULL,
`returndate` DATE NULL,
PRIMARY KEY (`bookno`),
FOREIGN KEY (stuNo)
        REFERENCES student(stuNo),
FOREIGN KEY (bookno)
        REFERENCES book(bookno)
        );

Results in enter image description here

点赞
评论
Liz
Liz

如果我想自己绘制er图,此代码应该是这样的吗?

 

CREATE TABLE student( stuNo INT NOT NULL, stuname VARCHAR(45) NULL, stusurname VARCHAR(45) NULL, class INT NULL, age INT NULL, PRIMARY KEY (stuNo));

CREATE TABLE typebook ( typeno INT NOT NULL, typename VARCHAR(45) NULL, PRIMARY KEY (typeno));

CREATE TABLE author( authorno INT NOT NULL, authorname VARCHAR(45) NULL, autorname VARCHAR(45) NULL, PRIMARY KEY (authorno));

CREATE TABLE book( bookno INT NOT NULL, bookname VARCHAR(45) NULL, authorno INT NOT NULL, typeno INT NOT NULL, PRIMARY KEY (bookno));

CREATE TABLE entry( stuNo INT NOT NULL, entryno INT NOT NULL, bookno INT NOT NULL, borrowdate DATE NULL, returndate DATE NULL );

<code>
点赞
评论