I would like your opinion about an Entity-Relationship Diagram of a POSTGRESQL script

Asked

Viewed 59 times

0

I am doing a work of the college whose goal is to make a database of a particular library and to elaborate an entity-relationship diagram of it , I made the script in postgresql but I have a lot of difficulty in the time to pass to make the diagram in brmodelo, Especially on the cardinality part, could you help me? Here is my library script. Below I will post the DER.

CREATE TABLE CATEGORIA(
ID SERIAL PRIMARY KEY,
DESCRICAO VARCHAR (50) NOT NULL
);

CREATE TABLE EDITORA(
ID SERIAL PRIMARY KEY,
NOME VARCHAR (50) NOT NULL
);

CREATE TABLE AUTOR(
ID SERIAL PRIMARY KEY,
NOME VARCHAR (50) NOT NULL
);

CREATE TABLE LIVRO(
  ID SERIAL PRIMARY KEY,
  NOME VARCHAR (50) NOT NULL,
  ID_CATEGORIA INT,
  ID_AUTOR INT,
  ID_EDITORA INT,
  FOREIGN KEY (ID_CATEGORIA) REFERENCES CATEGORIA(ID),
  FOREIGN KEY (ID_AUTOR)     REFERENCES AUTOR(ID),
  FOREIGN KEY (ID_EDITORA) REFERENCES EDITORA(ID)
);

THE DER: inserir a descrição da imagem aqui

  • Hello Emanoel! Welcome to our community. I will prepare an answer and I publish it for you.

  • Thank you, Matthew! Waiting :D

  • Your DML does not correspond to the diagram. According to your DML a book is related to 0 or 1 category (same author and publisher). In his diagram a book is related to N categories (same author and publisher). To implement an N:N relationship you need to create an auxiliary table in your physical model, so there should be a Book-Author table that relates each author with all of their books and each book with all of its authors (same category and publisher). Its model predicts that a book may have several publishers?

  • opa amigo, I edited the cardinalities. would be that way ?

  • @anonimo forgive me the correction: DDL (Data Definition Language). DML is Manipulation (Manipulation of data, not of structures). Creation of tables is DDL ;-)

  • @Matthew: right. My fault.

  • @Manoel: now corresponds to your DDL, it remains to know if it corresponds to reality being modeled, but you have not posted anything that could elucidate this points. For example in the real world a book may have several authors and an author may write several books, it would be a relationship N:N.

  • In brmodelo (which they ask us to do) there is no relationship N:N, the correct one would be 0:N?

  • A relationship (A) N:N (B) is translated, in the physical model, into (A) 0:N (A-B) N:0 (B), i.e., an intermediate table is created with the combination of foreign keys. I don’t know this model but you may already have to create these intermediate tables in it.

Show 4 more comments

1 answer

0

The MER (relationship entity model) should be the starting point for you Elaborate your exercise. Of course, later you will develop your own Method to be able to accurately map entities, their relationships and transform Is

With practice, you will realize that it is much easier to view the model in reverse (from the bank to the model and realize the deficiencies).

Instead of answering your question completely and, incidentally, designing it depends a lot on the level you want to reach, we can simplify too much or leave too complete (this is the risk that all modeling runs)I will propose to answer your question in a way that will teach you to reflect on abstraction and modeling. That’s what you need from what I noticed in your question. And it’s not hard.

Come on...

Nouns tend to be Entities in the Model: Verbs tend to be roles / relationships

Nouns: Book, Author, Publisher

Now let’s think about the verbs to see the relationships between the entities (all in the singular)

Book is CLASSIFIED in Category <<>> Category CLASSIFIES book

Author REDIGE Book <<>> Book is WRITTEN by Author

Translator Translates Book <<>> Book is TRANSLATED by Translator

(But why do we need to think about the proofreading translators etc? Because in a library system the classification considers several data, look at the catalogue of a book).

Editora PUBLICA Livro Book is PUBLISHED by Publisher

When the book is published, there is an edition! Therefore it is not the Book that is published, but the EDITION of it, which it has, number, date etc.

Now, let’s take a closer look at the relationships

Does the Publishing House actually publish the Book? No, physically the publication is associated with an edition that has print run, edition, date, revision and many other attributes.

Author writes book? How does co-author? And the translator? Wouldn’t it be better instead to have an Entity called AUTHOR have a so-called person, and it takes on a participation role? Oops! Participation? In what? Participation in the Book.

Then see an example for entities only:

PERSON <<<< PARTICIPATION >>>> BOOK

The rest I’ll leave for you to finish your work ;-) (Train a lot modeling!)

inserir a descrição da imagem aqui

**Now the pump for you to think: ** BUT WHAT WOULD MY MODEL LOOK LIKE IF IN THE SECOND EDITION THE TRANSLATOR WERE SOMEONE ELSE FROM A PARTICULAR BOOK? By the way, what if we changed the name of the relationship Participation to "Edition"? (now it’s time for you to exercise around :-D)

  • Wow, Matthew. I really appreciate your time and advice. According to my college classmates this model ain’t accepted, I haven’t seen him in class or in the book. It has to be DER created in Brmodelo, following the concepts of the one I posted :(

  • @emaonel.exe MER is one thing DER is another. When I saw your tables, I soon noticed that you didn’t think about the CONCEPTUAL modeling that is using the MER. The ERI comes later. Do this exercise the way I’m guiding you, not to deliver, to learn. Delivering, is not the ultimate goal. In fact, Brmodelo is useless in companies. Nor should it be taught more in graduation. Because in addition to being full of bugs, it only works on Windows and when you give it a z control it adds everything (in some versions) does not have the most classic notation of the modeling that is that of Peter Chen. Show that answer to your teacher.

  • @emaonel.exe this class should be used to better understand: https://course.ccs.neu.edu/cs3200sp18s2/download/L08-ER.pdf

  • Okay. I’ll take a look. Obg

Browser other questions tagged

You are not signed in. Login or sign up in order to post.