There are several main steps in the database design process:
Before diving into developing the SQL CREATE TABLE statements required to build a database, it proves necessary to first develop a plan for the kind of information the database will need to store. To support this planning, we need a way to model the components of the database (tables, columns, rows, and constraints) and capture the design decisions that affect how such components are configured in SQL. This model should allow rapid prototyping of our table design and relationship but also be standard and specific enough to easily transition from the model to implementation via SQL CREATE TABLE statements. Database designers use the Entity-Relationship (ER) Model for exactly this purpose. An ER Model consists of
We use the word entity to describe both the thing we wish to track, an entity class, and
and actual occurrence of that entity in our model, an entity instance.
As an example,
an entity class would be midshipmen and another entity class would be courses
or grades. The entities will eventually be stored as tables. The values we desired to
track about an entity, which we will store as a table columns, are known as entity attributes. Once we
provide these values (for example alpha, first name, last name, etc.), we are
creating a specific entity instance (a midshipman)! In the example below, we wish to track information about customers, the entity class, and there are a few attributes concerning the customers that we wish to store.
Throughout this course, texts, and notes, entities will be presented in different ways.
Identifiers are those attributes that can identify specific instances of an entity. The identifiers in the data model become the keys in the database design, and just as before we have composite identifiers consisting of two or more attributes that when combined can uniquely identify an entity.
Relationships describe the associations between entities, they have no attributes, but can have a degree.
Cardinality refers to a count, and in terms of ER Models, we use cardinality to represent the minimum and maximum number of entity instances that can participate in a relationship. There are two types of cardinalities that characterize a relationship between two entities:
We will commonly use crow's foot notation for representing the cardinality in an Entity Relationship Diagram. This notation allows us to quickly see from a drawing what the allowable links are within the model.
An ID-Dependent Entity can apper in a one-to-many relationship where the child entity (the entity on the "many" side) has an identifier that includes the identifier of the parent entity. As an example, an apartment entity would be the child to a building entity. The minimum cardinality from the ID-dependent entity to the parent is always one, because the child must have the parent to exist! In the following example the solid line between the entities indicates an identifying relationship.
In summary, here are some important traits about identifying relationships:
An ID-Independent Entity, or strong entity, can exist on its own without depending on a parent existing first. As an example, an employee can exist without a skill, say the employee is still in training and has not qualified for any desired skills yet. Vice-versa, a skill can exist without currently having any employees who have that skill...maybe it's time to hire a new employee that does! The dashed lines in the ER diagrams for EMPLOYEE and SKILL in the Notation section above are what declares this as a non-identifying relationship in our ER Model.
In summary, here are some important traits about non-identifying relationships:
Subtype entities are special cases of a supertype entity, where all common attributes are held in the supertype while specific subtype attributes are held in the subtype entity. Consider the EMPLOYEE entity we have seen thus far, it is possible to have different types of employees, such as managers or database administrators. Both examples are employees but we may want to store specific information based on their subtype, such as what database a DB admin is responsible for, or what level in the organization a manager is currently employed at.
The examples provided above when discussing cardinality were HAS-A relationships, where object A has an object B. Subtype/supertype relationships are IS-A relationship, where the subtype is a more specific entity then their supertype, for example a database administrator is an employee.
Draw the ER diagram to meet the following requirements.
Assuming we want to store data about a vegetable garden, create an ER diagram for a Vegetable entity, a Plot entity, and an Observation entity. I plan on having a cabinet full of different Vegetable seeds, and I'll be planting seeds in the plots. I might plant the same vegetable in different plots, and I might not plant every type of vegetable I have inventory for. Some plots might also be vacant. There are different kinds of plots: I'll have cold-frames, planters, and square foot gardens. Throughout the season I'll be making observations about the status of my plants growing.
Come up with your own scenario/requirements for a database. Describe the scenario in plain English, then draw the ER diagram. Make sure you have strong and weak entities, different kinds of cardinality, and both is-a and has-a replationships.