Database Design Example Phase 2: Design

This article follows on from Database Design Example Phase 1: Analysis.

Based on the provided information, you can begin your logical design and should be able to identify the initial entities:

  • Poet
  • Poem
  • Publication
  • Sale
  • Customer

The Poet's Circle is not an entity, or even of instance an a publisher entity. Only if the system were developed for many publishers would publisher be a valid entity.

Neither website nor poetry community are entities. There is only one website, and anyway, a website is merely a means of producing data to populate the database. There is also only one poetry community as far as this system is concerned, and there is not much you'd want to store about it.

Next, you need to determine the relationship between these entities. You can identify the following:

  • A poet can write many poems. The analysis identified the fact that a poet can be stored in the system even if there are no associated poems. Poems may be captured at a later point in time, or the poet may still be a potential poet. Conversely, many poets could conceivably write a poem, though the poem must have been written by at least one poet.
  • A publication may contain many poems (an anthology) or just one. It can also contain no poems (poetry criticism for example). A poem may or may not appear in a publication.
  • A sale must be for at least one publication, but it may be for many. A publication may or may not have made any sales.
  • A customer may be made for many sales, or none at all. A sale is only made for one and only one customer.

You can identify the following attributes:

  • Poet: first name, surname, address, email address
  • Poem: poem title, poem contents
  • Publication: title, price
  • Sales: date, amount
  • Customer: first name, surname, address, email address

Based on these entities and relationships, you can construct the entity-relationship diagram shown below:

poets-circle-erd1

There are two many-to-many relationships in the figure above. These need to be converted into one-to-many relationships before you can implement them in a DBMS. After doing so, the intersection entities poem-publication and sale-publication are created.

poets-circle-erd2

Now, to begin the logical and physical design, you need to add attributes that can create the relationship between the entities and specify primary keys. You do what's usually best, and create new, unique, primary keys. The following tables show the structures for the tables created from each of the entities:

Poet table

FieldDefinition
poet codeprimary key, integer
first namecharacter (30)
surnamecharacter (40)
addresscharacter (100)
postcodecharacter (20)
email addresscharacter (254)

Poem table

FieldDefinition
poem codeprimary key, integer
poem titlecharacter(50)
poem contentstext
poet codeforeign key, integer

Poem-publication table

FieldDefinition
poem codejoint primary key, foreign key, integer
publication codejoint primary key, foreign key, integer

Publication table

FieldDefinition
publication codeprimary key, integer
titlecharacter(100)
pricenumeric(5.2)

Sale-publication table

FieldDefinition
sale codejoint primary key, foreign key, integer
publication codejoint primary key, foreign key, integer

Sale table

FieldDefinition
sale codeprimary key, integer
datedate
amountnumeric(10.2)
customer codeforeign key, integer

Customer table

FieldDefinition
customer codeprimary key, integer
first namecharacter (30)
surnamecharacter (40)
addresscharacter (100)
postcodecharacter (20)
email addresscharacter (254)

MariaDB will have no problem with this, and is selected as the DBMS. Existing hardware and operating system platforms are also selected. The following section looks at the implementation and the SQL statements used to create the MariaDB tables.

Comments

Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.