Contents
Business Narrative and Data Model
Summary of the ER Modeling Process
Our ER Model of the European Parliament
This text on SQL is based on the Oracle Database using the EP-European Parliament as Data Model.
The European Parliament (EP) is the parliamentary institution of the European Union (EU).
The European Parliament is elected by the citizens of the European Union to represent their interests.
Its origins go back to the 1950s and the founding Treaties. Since 1979 its members have been directly elected by the citizens of the EU.
Elections are held every five years, and every EU citizen is entitled to vote, and to stand as a candidate, wherever they live in the EU. Parliament thus expresses the democratic will of the European Union's nearly 500 million citizens and it represents their interests in discussions with the other EU institutions.
The European Parliament model and data used in this SQL text, are based on the elections which were held in June 2004. The European Parliament of 2004 elections had 785 members from all 27 EU countries.
The sources for the data, which are all freely obtainable from the European Union website, and from several leaflets of the EU institutions, are listed in the References section.
These sources are used to create the fictitious Business Narrative of the "Data Modelling and Normalization" Chapter.
We called this Business Narrative; "the Story of the European Union" which explains about the EU and EP, for purposes of Data Modeling.
The Story of the European Union is the last Chapter of Kaye is Learning SQL.
To design a database, we follow a method or a technique called Entity Relationship Modeling.
Throughout the text, we use the abbreviation ER for Entity Relationship.
A model is a simplified representation, which is used to explain a real world system or a real world event.
From Wikipedia - The Free Encyclopedia
From Wiktionary - a wiki based Open Content Dictionary
A Model is a simplified representation used to explain the workings of a real world system or event. For example, a Computer Weather Model which predicts the path of the hurricane.
A model is a structural design of a complex system. For example, a Business Model.
A Model is a miniature representation of a physical object. For example, a Model of a World War II Fighter Plane.
An ER Model separates "the information required by a business" from "the activities/processes performed within a business".
Although businesses can change their activities, the type of information they need to keep tends to remain unchanged.
We need an ER Model to specify the information needs of our organization.
The objective is "to produce a model;
Please remember we have mentioned in the previous chapter (Relational Approach), that;
a Business User can be:
an IT Staff can be:
An ER Model must be clear enough to be understood by the Business Users, and it should hold enough information fot the IT Staff to be able to build a Database System.
An ER Model documents information for the organization in a clear, precise format.
An ER Model provides an easily understood picture of the database.
The building blocks of an ER Model are;
We have already briefly learned about Entities, Attributes and Relationships in the previous chapter (Relational Approach), but now we will examine them once more within the context of the Entity Relationship Model.
When an Entity has a Relationship with itself, there is a recursive relationship, and the Entity is called a 'Self-Referencing Entity'.
To create an ER Model, we start by creating a 'Business Narrative'.
The 'Business Narrative' will tell us;
"the pieces of information required for the business of our organization to function today and in the future".
Using this Business Narrative, we will;
I am a Business Analyst working in the IT Organization of the European Union. One of my team's main tasks these days is to create a Business Information System that can be used by all the employees and users of my organization.
The best way to learn this story, that is, the Story of the European Union is, to listen to the employees who work in our organization.
Please Note:
ER Models are derived from Business Narratives or Business Specifications.
The Business Narrative describes Things of Significance.
These Things of Significance are mapped into ENTITIES of the ER MODEL.
The Business Narrative also describes the Details of the Things of Business Significance.
These detailed descriptions are mapped into the ATTRIBUTES of the ER MODEL.
The Business Narrative describes the RELATIONSHIPS between ENTITIES as well.
We listened to the story of the European Union as told by the employees in the EU Institutions. We will now concentrate on the European Parliament which is sufficient enough for our purposes of learning about the Elementary Basics of a Database.
The Business Narrative says:
The European Parliament is the parliamentary institution of the European Union. The European Parliament (EP) is elected by the citizens of the European Union to represent their interests. Its origins go back to the 1950s and the founding Treaties. Since 1979 its members have been directly elected by the citizens of the EU.
Elections are held every five years, and every EU citizen is entitled to vote, and to stand as a candidate, wherever they live in the EU. Parliament thus expresses the democratic will of the Union’s nearly 500 million citizens and it represents their interests in discussions with the other EU institutions.
The latest elections were in June 2004. Parliament has 785 members from all 27 EU countries.
...
...
Members of the European Parliament (MEPs) do not sit in national blocks, but in EU-wide political groups. Between them, they represent all views on political issues and European integration, from the strongly pro-federalist to the openly Eurosceptic. A political group comprises Members elected in at least one fifth of the EU countries and has a minimum of 20 Members.
There are currently seven political groups in the European Parliament. Members who do not belong to any of the groups are known as 'non-attached Members non-inscrits (NI)'. Political groups have their own staff and the Members have parliamentary assistants.
...
...
Note:
The add-on narrative seen below is FICTITIOUS solely for purposes of teaching some of the SQL concepts.
The concept of role multipliers of the MEPs are completely fictitious. The data for the attributes 'salary' and 'role multipliers' are made-up. These attributes are used later on in SQL concepts like NULLs in Arithmetic Operators and Group Functions and as well as in some other topics.
As well as telling about the structure and workings of the European Parliament, the employees in the EP added on the following:
We want to track some basic information on the EU COUNTRIES. For each EU COUNTRY, we want to track information like country name, capital city, population, area, gdp, purchasing power standard and so on. We would like to track information on not only the current member countries but also on candidate countries, and some other countries about which statistical data is held by EUROSTAT the statistical office of the European Communities. We call this the status of the country.
We want to track some basic information on the POLITICAL GROUPs also. For each POLITICAL GROUP, we want to track the political group name, location, address, telephones, e-mails, website information as well as a description of the aim of the POLITICAL GROUP. We would like to track information on the MEMBERS OF THE EUROPEAN PARLIAMENT also. We have to track their names, e-mails, telephones, salaries and so on.
Most of the MEMBERS OF THE EUROPEAN PARLIAMENT(MEPs) have more than one task they perform. For example, an MEP can be a Chair or a Co-Chair or a Vice-President or a Queastor and at the same time, an MEP takes part in several Commissions and Delegations. For example, an MEP can be a Member in one Delegation, and a Chair in another Delegation or a Commission. We need a multiplier for each of these roles. The role multiplier helps us to calculate the total salary of an MEP. We would like to track all these roles.
A POLITICAL GROUP of the EP comprises Members elected in at least one fifth of the EU COUNTRIES and has a minimum of 20 MEMBERS OF THE EUROPEAN PARLIAMENT(MEPs).
An EU COUNTRY may have many MEMBERS OF THE EUROPEAN PARLIAMENT(MEPs) who belong to various POLITICAL GROUPs of the EP.
However, a MEMBER OF THE EUROPEAN PARLIAMENT(MEP) must belong to one and only one POLITICAL GROUP in the European Parliament and an MEP is a citizen of one and only one EU COUNTRY.
The relationship can be read from Left to Right to tell us that:
Each EU Country MAY have many MEPs who belong to many Political Groups of the EP.
The relationship can be read from Right to Left to tell us that:
Each Political Group of the EP MUST comprise of at least 20 MEPs elected in at least one fifth of the EU Countries.
As we can see in the "ER Model of the COUNTRY and the POLITICAL GROUP" of the previous section, there are some Conventions we must follow when we draw/create Entity Diagrams.
These Conventions are summarized below.
Summary of Entity Diagramming Conventions
One of the types of Relationships between Entities can be classified as follows:
These types of Relationships between Entities are called Connectivity or Multiplicity.
At the Many (One or More) end, the relationship line joins a Softbox at three points, known as a "crowsfoot" or a "triangle".
At the One (One and Only One) end, the line joins a Softbox at one point or sometimes alternatively with vertical lines.
Connectivity of a Relationship
The Relationship between Two Entities can be given using the lower and upper limits .
This information is called the Cardinality.
The Cardinality is written Next to Each Entity in the form (m,n), where:
An example is shown diagrammatically below.
Each EU Country may have many MEPs who belong to many Political Groups of the EP.
Each Political Group of the EP must comprise at least 20 MEPs who are elected in at least one fifth of the EU Countries.
The Two Entities that have a Relationship in this diagram are the EU COUNTRY and the EP POLITICAL GROUP.
Therefore, the CARDINALITY information displayed contain only the numbers given in the Relationships of these Two Entities.
Currently there are 27 EU Member countries and one fifth is approximately five. Thus the minimum Cardinality for an EU COUNTRY is 5.
Please Note:
Each relationship has an Optionality.
A Relationship can be:
Mandatory Relationship
Where a Relationship End is Mandatory, a Solid Line is drawn for that half of the Relationship.
Optional Relationship
Where the Relationship End is Optional, a Broken or Dashed Line is drawn for that half of the Relationship.
An Optional Relationship can occur in the following Connectivities:
An Optional Relationship can also occur on ONE OR BOTH SIDES of the Relationship.
Let's have a look at the ER Diagram of the EU COUNTRY and the EP POLITICAL GROUP we have seen earlier.
This ER Diagram has an Optional Relationship on one end, and a Mandatory Relationship on the other end:
Reading from Left to Right:
Each EU COUNTRY MAY have many MEPs who belong to many EP POLITICAL GROUPs.
Reading from Right to Left:
Each EP POLITICAL GROUP MUST comprise of at least 20 MEPs elected in at least one fifth of the EU COUNTRIES.
Using the Conventions given so far, we come up with a Formula to Read an ER Diagram.
This is how we Read the ER Diagram above:
From Left to Right
Each ENTITY-A MUST be Relation_Name_1 One and Only One ENTITY-B.
From Right to Left
Each ENTITY-B MAY be Relation_Name_2 One or More ENTITY-A(s).
Attribute Representation
An Attribute is represented by writing its name;
Attribute Names
Attribute Optionality
Each attribute has an Optionality. The Optionality of an attribute is identified by using an Attribute Tag.
The Definitions we have looked at so far for Entity, Relationship and Attribute are all Definitions that represent a Class or a Type – Not an Instance.
We will now see the difference between an Entity Class and an Entity Instance.
Below is an Entity Class in our Data Model:
An Entity Instance is a single occurrence of an Entity Class.
There is only one Entity Class of EU COUNTRY, whereas there are twenty-seven Instances of this Entity.
Below are some of the Instances of the Entity Class EU COUNTRY.
Please note that not all attributes are displayed.
Entity Class | country id | country name | status | join date | capital | currency name |
---|---|---|---|---|---|---|
Instance 1 | AT | Austria | M | 01-JAN-95 | Vienna | Euro |
Instance 2 | BE | Belgium | M | 25-MAR-57 | Brussels | Euro |
Instance 3 | BG | Bulgaria | M | 01-JAN-07 | Sofia | Bulgarian Lev |
The Unique Identifier (UID) May Be:
Unique Identifier Diagramming Conventions
This is also explained in the Composite Entity section of Normalization .
A Domain is the Set of Values that may be assigned to an Attribute.
The Values of the Domain of an Attribute can be;
These values are formed and restrained by;
Example:
We can define the Domain for the Values of the Attribute 'role title' of the entity ROLE can take.
Some of the Values in the Domain of this Attribute are:
Example:
For the "salary" attribute of the MEP entity, we can set a Minimum Salary Value and a Maximum Salary Value.
For example, the minimum salary value = 10000, and the maximum salary value = 30000.
These Minimum and Maximum values define a Range for the Salary.
Then we can say that, the Domain of the attribute "salary" consists of values between 10000 and 30000.
Example:
Let's say we have an entity which holds details of the European Institutes in our Data Model, called EU INSTITUTES.
"institute_name" is one of the attributes of this entity.
We know that;
Another way of saying this is that;
The Attribute or the Combination of Attributes designated as the Primary Key, Uniquely Identifies an Entity Instance in an Entity.
These attributes are called "Key Attributes".
An Entity may also have Attributes which DO NOT make up the Primary Key of the Entity.
Such Attributes are called "Non-Key Attributes".
A "Non-Key Attribute" or any "Combination of Non-Key Attributes" CAN NOT Uniquely Identify an Entity Instance in an Entity.
The "Non-Key Attributes" are Functionally Dependent on the "Key Attributes".
We will now investigate the concepts of;
Let's assume that we have just created a Database, and then we created just one Entity in it. All the data about our Business is in this Entity.
We call this entity "European Parliament Seats" or "EP SEATS".
EP SEATS entity has the following entity instances:
/ | pg code | country code | # of seats | pg name | country name | pg chairman / co-chair 1 | co-chair 2 | pop | capital | pop of capital | # of universities in capital |
---|---|---|---|---|---|---|---|---|---|---|---|
Inst 1 | EPP-ED | BE | 6 | Group of EPP-ED | Belgium | Joseph Daul | 10.6 | Brussels | 1.03 | 14 | |
Inst 2 | EPP-ED | BG | 5 | Group of EPP-ED | Bulgaria | Joseph Daul | 7.64 | Sofia | 1.39 | 16 | |
Inst 3 | EPP-ED | DK | 1 | Group of EPP-ED | Denmark | Joseph Daul | 5.48 | Copenhagen | 0.35 | 2 | |
Inst 4 | EPP-ED | DE | 49 | Group of EPP-ED | Germany | Joseph Daul | 82.27 | Berlin | 3.4 | 28 | |
Inst 5 | EPP-ED | MT | 2 | Group of EPP-ED | Malta | Joseph Daul | 0.4 | Valetta | 0.006 | 1 | |
Inst 6 | Greens/EFA | BE | 2 | Group of Greens/EFA | Belgium | Monica Frassoni | Daniel Cohn Bendit | 10.6 | Brussels | 1.03 | 14 |
Inst 7 | Greens/EFA | DK | 1 | Group of Greens/EFA | Denmark | Monica Frassoni | Daniel Cohn Bendit | 5.48 | Copenhagen | 0.35 | 2 |
Inst 8 | Greens/EFA | DE | 13 | Group of Greens/EFA | Germany | Monica Frassoni | Daniel Cohn Bendit | 82.27 | Berlin | 3.4 | 28 |
Inst 9 | PES | BE | 7 | Socialist Group | Belgium | Martin Schulz | 10.6 | Brussels | 1.03 | 14 | |
Inst 10 | PES | BG | 5 | Socialist Group | Bulgaria | Martin Schulz | 7.64 | Sofia | 1.39 | 16 | |
Inst 11 | PES | DK | 5 | Socialist Group | Denmark | Martin Schulz | 5.48 | Copenhagen | 0.35 | 2 | |
Inst 12 | PES | DE | 23 | Socialist Group | Germany | Martin Schulz | 82.27 | Berlin | 3.4 | 28 | |
Inst 13 | PES | MT | 3 | Socialist Group | Malta | Martin Schulz | 0.4 | Valetta | 0.006 | 1 | |
Inst 14 | ALDE | LU | 1 | Group of ALDE | Luxembourg | Graham Watson | 0.48 | Luxembourg | 0.076 | 3 |
The Entity EP SEATS does not have any Single Attribute that can Uniquely Identify an Entity Instance.
The first choice for a Unique Identifier would be the attribute political group ("pg code").
However, the values of the attribute political group ("pg code") are not unique, because a political group exists in more than one country ("country code").
For example, the attribute value 'Greens/EFA' for the attribute "pg code", exists in instances 6, 7, and 8, for "country code" values of 'BE', 'DK', and 'DE', as seen in the image below.
/ | pg code | country code | # of seats | pg name | country name | pg chairman / co-chair 1 | co-chair 2 | pop | capital | pop of capital | # of universities in capital |
---|---|---|---|---|---|---|---|---|---|---|---|
Inst 6 | Greens/EFA | BE | 2 | Group of Greens/EFA | Belgium | Monica Frassoni | Daniel Cohn Bendit | 10.6 | Brussels | 1.03 | 14 |
Inst 7 | Greens/EFA | DK | 1 | Group of Greens/EFA | Denmark | Monica Frassoni | Daniel Cohn Bendit | 5.48 | Copenhagen | 0.35 | 2 |
Inst 8 | Greens/EFA | DE | 13 | Group of Greens/EFA | Germany | Monica Frassoni | Daniel Cohn Bendit | 82.27 | Berlin | 3.4 | 28 |
As seen in the image above, "pg code" is not unique to uniquely identify these three instances.
Hence, "pg code" cannot be chosen as the Primary Key.
The attribute "country code" cannot uniquely identify an entity instance either.
There may be more than one political group ("pg code") in a country ("country code").
Therefore "country code" can repeat in more than one instance.
For example, the attribute value 'BE' for the attribute "country code", repeats in instances 1, 6, and 9 for "pg code" values of 'EPP-ED', 'Greens/EFA', and 'PES', as seen in the image below.
/ | pg code | country code | # of seats | pg name | country name | pg chairman / co-chair 1 | co-chair 2 | pop | capital | pop of capital | # of universities in capital |
---|---|---|---|---|---|---|---|---|---|---|---|
Inst 1 | EPP-ED | BE | 6 | Group of EPP-ED | Belgium | Joseph Daul | 10.6 | Brussels | 1.03 | 14 | |
Inst 6 | Greens/EFA | BE | 2 | Group of Greens/EFA | Belgium | Monica Frassoni | Daniel Cohn Bendit | 10.6 | Brussels | 1.03 | 14 |
Inst 9 | PES | BE | 7 | Socialist Group | Belgium | Martin Schulz | 10.6 | Brussels | 1.03 | 14 |
As seen in the image above, the attribute "country code" is not unique to uniquely identify these instances.
Hence, "country code" cannot be chosen as the Primary Key, either.
In each Instance, Combination of "pg code" and "country code" are Unique.
For example, in Instance 1, the Combination of 'EPP-ED' and 'BE' make up a Unique Value which identifies this instance.
/ | pg code | country code | # of seats | pg name | country name | pg chairman / co-chair 1 | co-chair 2 | pop | capital | pop of capital | # of universities in capital |
---|---|---|---|---|---|---|---|---|---|---|---|
Inst 1 | EPP-ED | BE | 6 | Group of EPP-ED | Belgium | Joseph Daul | 10.6 | Brussels | 1.03 | 14 |
Combination of the attributes "pg code" and "country code" is the UID (the Unique Identifier) for the entity EP SEATS.
For each instance, the combination of "pg code" and "country code" uniquely identifies that instance.
Hence we can say that;
This Entity has a Composite Primary Key, which consists of "pg code" and "country code".
The attributes "pg code" and "country code" are the "Key Attributes" of this entity.
All attributes other than "pg code" and "country code" in the entity EP SEATS, are "Non-Key Attributes".
The "Non-Key Attributes" are;
/ | Component One of the Composite Primary Key (Key Attribute) | Component Two of the Composite Primary Key (Key Attribute) | Non-Key Attribute | Non-Key Attribute | Non-Key Attribute | Non-Key Attribute | Non-Key Attribute | Non-Key Attribute | Non-Key Attribute | Non-Key Attribute | Non-Key Attribute |
---|---|---|---|---|---|---|---|---|---|---|---|
/ | pg code | country code | # of seats | pg name | country name | pg chairman / co-chair 1 | co-chair 2 | pop | capital | pop of capital | # of universities in capital |
Inst 1 | EPP-ED | BE | 6 | Group of EPP-ED | Belgium | Joseph Daul | 10.6 | Brussels | 1.03 | 14 |
There can be Three Types of Dependencies in an Entity:
Partial Dependency on "pg code"
In the sample entity EP SEATS, the attributes "pg name", "pg chairman / co-chair 1" and "co-chair 2" are only dependent on one Component of the Composite Primary Key on the attribute "pg code".
/ | Component One of the Composite Primary Key (Key Attribute) | Component Two of the Composite Primary Key (Key Attribute) | Non-Key Attribute | Non-Key Attribute Dependent on
Component One of the Composite Primary Key
PARTIAL DEPENDENCY |
Non-Key Attribute | Non-Key Attribute Dependent on
Component One of the Composite Primary Key
PARTIAL DEPENDENCY |
Non-Key Attribute Dependent on
Component One of the Composite Primary Key
PARTIAL DEPENDENCY |
Non-Key Attribute | Non-Key Attribute | Non-Key Attribute | Non-Key Attribute |
---|---|---|---|---|---|---|---|---|---|---|---|
/ | pg code | country code | # of seats | pg name | country name | pg chairman / co-chair1 | co-chair 2 | pop | capital | pop of capital | # of universities in capital |
Inst 6 | Greens/EFA | BE | 2 | Group of Greens/EFA | Belgium | Monica Frassoni | Daniel Cohn Bendit | 10.6 | Brussels | 1.03 | 14 |
Therefore, the Non-Key Attributes "pg name", "pg chairman / co-chair 1" and "co-chair 2" are Partially Dependent on the Composite Primary Key.
Partial Dependency on "country code"
In the sample entity EP SEATS, the attributes "country name", "pop" and "capital" are only dependent on one Component of the Composite Primary Key on the attribute "country code".
/ | Component One of the Composite Primary Key (Key Attribute) | Component Two of the Composite Primary Key (Key Attribute) | Non-Key Attribute | Non-Key Attribute | Non-Key Attribute Dependent on
Component Two of the Composite Primary Key
PARTIAL DEPENDENCY |
Non-Key Attribute | Non-Key Attribute | Non-Key Attribute Dependent on
Component Two of the Composite Primary Key
PARTIAL DEPENDENCY |
Non-Key Attribute Dependent on
Component Two of the Composite Primary Key
PARTIAL DEPENDENCY |
Non-Key Attribute | Non-Key Attribute |
---|---|---|---|---|---|---|---|---|---|---|---|
/ | pg code | country code | # of seats | pg name | country name | pg chairman / co-chair1 | co-chair 2 | pop | capital | pop of capital | # of universities in capital |
Inst 6 | Greens/EFA | BE | 2 | Group of Greens/EFA | Belgium | Monica Frassoni | Daniel Cohn Bendit | 10.6 | Brussels | 1.03 | 14 |
Therefore, the Non-Key Attributes "country name", "pop" and "capital" are Partially Dependent on the Composite Primary Key.
A Non-Key Attribute dependent on All of the Primary Key Attributes shows Full Dependency.
The attribute "# of seats" is Dependent On All the Components of the Primary Key the "pg code" and the "country code".
/ | Component One of the Composite Primary Key (Key Attribute) | Component Two of the Composite Primary Key (Key Attribute) |
Non-Key Attribute Dependent on All of the
Primary Key Attributes
FULL DEPENDENCY |
Non-Key Attribute | Non-Key Attribute | Non-Key Attribute | Non-Key Attribute | Non-Key Attribute | Non-Key Attribute | Non-Key Attribute | Non-Key Attribute |
---|---|---|---|---|---|---|---|---|---|---|---|
/ | pg code | country code | # of seats | pg name | country name | pg chairman / co-chair 1 | co-chair 2 | pop | capital | pop of capital | # of universities in capital |
Inst 1 | EPP-ED | BE | 6 | Group of EPP-ED | Belgium | Joseph Daul | 10.6 | Brussels | 1.03 | 14 |
Therefore, the Non-Key Attribute "# of seats" is Fully Dependent on the Primary Key.
In Transitive Dependency, a Non-Key Attribute is Dependent On Another Non-Key Attribute, which is Partially or Fully Dependent On the Primary Key.
The Non-Key Attributes "pop of capital" and "# of universities in capital" are Neither Dependent On Both of the Components of the Composite Primary Key, Nor On Only One of the Component of the Composite Primary Key.
These Non-Key Attributes are Dependent On the attribute "capital", which is another Non-Key Attribute and which is Partially Dependent on the Primary Key.
/ | Component One of the Composite Primary Key (Key Attribute) | Component Two of the Composite Primary Key (Key Attribute) | Non-Key Attribute | Non-Key Attribute | Non-Key Attribute | Non-Key Attribute | Non-Key Attribute | Non-Key Attribute | Non-Key Attribute Dependent on Component Two of the Composite Primary Key (Partially Dependent on the Primary Key) | Non-Key Attribute Dependent on Another Non-Key Attribute (capital)
which is Partially Dependent on the Primary Key;
TRANSITIVE DEPENDENCY |
Non-Key Attribute Dependent on Another Non-Key Attribute (capital)
which is Partially Dependent on the Primary Key;
TRANSITIVE DEPENDENCY |
---|---|---|---|---|---|---|---|---|---|---|---|
/ | pg code | country code | # of seats | pg name | country name | pg chairman / co-chair1 | co-chair 2 | pop | capital | pop of capital | # of universities in capital |
Inst 6 | Greens/EFA | BE | 2 | Group of Greens/EFA | Belgium | Monica Frassoni | Daniel Cohn Bendit | 10.6 | Brussels | 1.03 | 14 |
Therefore, the Non-Key Attributes "pop of capital" and "# of universities in capital" have Transitive Dependency on the Primary Key.
"pg code" related Redundancy
In the Sample Entity EP SEATS, values of "pg name", "pg chairman / co-chair 1", "co-chair 2" are repeated for the same political group, from one instance to the other.
As an example, we can see the Instances 6, 7, and 8, for the "pg code" values of 'Greens/EFA', which are highlighted in the image below.
Although not highlighted in the image below, there is a parallel redundancy for the "pg code" values of 'EPP-ED' and 'PES', also.
/ | pg code | country code | # of seats | pg name | country name | pg chairman / co-chair 1 | co-chair 2 | pop | capital | pop of capital | # of universities in capital |
---|---|---|---|---|---|---|---|---|---|---|---|
Inst 1 | EPP-ED | BE | 6 | Group of EPP-ED | Belgium | Joseph Daul | 10.6 | Brussels | 1.03 | 14 | |
Inst 2 | EPP-ED | BG | 5 | Group of EPP-ED | Bulgaria | Joseph Daul | 7.64 | Sofia | 1.39 | 16 | |
Inst 3 | EPP-ED | DK | 1 | Group of EPP-ED | Denmark | Joseph Daul | 5.48 | Copenhagen | 0.35 | 2 | |
Inst 4 | EPP-ED | DE | 49 | Group of EPP-ED | Germany | Joseph Daul | 82.27 | Berlin | 3.4 | 28 | |
Inst 5 | EPP-ED | MT | 2 | Group of EPP-ED | Malta | Joseph Daul | 0.4 | Valetta | 0.006 | 1 | |
Inst 6 | Greens/EFA | BE | 2 | Group of Greens/EFA | Belgium | Monica Frassoni | Daniel Cohn Bendit | 10.6 | Brussels | 1.03 | 14 |
Inst 7 | Greens/EFA | DK | 1 | Group of Greens/EFA | Denmark | Monica Frassoni | Daniel Cohn Bendit | 5.48 | Copenhagen | 0.35 | 2 |
Inst 8 | Greens/EFA | DE | 13 | Group of Greens/EFA | Germany | Monica Frassoni | Daniel Cohn Bendit | 82.27 | Berlin | 3.4 | 28 |
Inst 9 | PES | BE | 7 | Socialist Group | Belgium | Martin Schulz | 10.6 | Brussels | 1.03 | 14 | |
Inst 10 | PES | BG | 5 | Socialist Group | Bulgaria | Martin Schulz | 7.64 | Sofia | 1.39 | 16 | |
Inst 11 | PES | DK | 5 | Socialist Group | Denmark | Martin Schulz | 5.48 | Copenhagen | 0.35 | 2 | |
Inst 12 | PES | DE | 23 | Socialist Group | Germany | Martin Schulz | 82.27 | Berlin | 3.4 | 28 | |
Inst 13 | PES | MT | 3 | Socialist Group | Malta | Martin Schulz | 0.4 | Valetta | 0.006 | 1 | |
Inst 14 | ALDE | LU | 1 | Group of ALDE | Luxembourg | Graham Watson | 0.48 | Luxembourg | 0.076 | 3 |
"country code" related Redundancy
Values of the attributes, "country name", "pop", "capital", "pop of capital" and "# of universities in capital" also repeat for the same country, from one instance to the other.
As an example, we can see the Instances 5 and 13, for the "country code" values of 'MT' which are highlighted in the image below.
Although not highlighted in the image below, there is a parallel redundancy for the "country code" values of 'BE', 'BG', 'DK' and 'DE', also.
/ | pg code | country code | # of seats | pg name | country name | pg chairman / co-chair 1 | co-chair 2 | pop | capital | pop of capital | # of universities in capital |
---|---|---|---|---|---|---|---|---|---|---|---|
Inst 1 | EPP-ED | BE | 6 | Group of EPP-ED | Belgium | Joseph Daul | 10.6 | Brussels | 1.03 | 14 | |
Inst 2 | EPP-ED | BG | 5 | Group of EPP-ED | Bulgaria | Joseph Daul | 7.64 | Sofia | 1.39 | 16 | |
Inst 3 | EPP-ED | DK | 1 | Group of EPP-ED | Denmark | Joseph Daul | 5.48 | Copenhagen | 0.35 | 2 | |
Inst 4 | EPP-ED | DE | 49 | Group of EPP-ED | Germany | Joseph Daul | 82.27 | Berlin | 3.4 | 28 | |
Inst 5 | EPP-ED | MT | 2 | Group of EPP-ED | Malta | Joseph Daul | 0.4 | Valetta | 0.006 | 1 | |
Inst 6 | Greens/EFA | BE | 2 | Group of Greens/EFA | Belgium | Monica Frassoni | Daniel Cohn Bendit | 10.6 | Brussels | 1.03 | 14 |
Inst 7 | Greens/EFA | DK | 1 | Group of Greens/EFA | Denmark | Monica Frassoni | Daniel Cohn Bendit | 5.48 | Copenhagen | 0.35 | 2 |
Inst 8 | Greens/EFA | DE | 13 | Group of Greens/EFA | Germany | Monica Frassoni | Daniel Cohn Bendit | 82.27 | Berlin | 3.4 | 28 |
Inst 9 | PES | BE | 7 | Socialist Group | Belgium | Martin Schulz | 10.6 | Brussels | 1.03 | 14 | |
Inst 10 | PES | BG | 5 | Socialist Group | Bulgaria | Martin Schulz | 7.64 | Sofia | 1.39 | 16 | |
Inst 11 | PES | DK | 5 | Socialist Group | Denmark | Martin Schulz | 5.48 | Copenhagen | 0.35 | 2 | |
Inst 12 | PES | DE | 23 | Socialist Group | Germany | Martin Schulz | 82.27 | Berlin | 3.4 | 28 | |
Inst 13 | PES | MT | 3 | Socialist Group | Malta | Martin Schulz | 0.4 | Valetta | 0.006 | 1 | |
Inst 14 | ALDE | LU | 1 | Group of ALDE | Luxembourg | Graham Watson | 0.48 | Luxembourg | 0.076 | 3 |
How can Redundant Data cause Huge Problems in Databases?
In the Entity EP SEATS, there is a very large amount of Redundancy in a total of only fourteen instances.
Redundant Data can cause huge problems in Databases.
First of all, someone has to enter the same data repeatedly.
We will now see two examples of this case.
Example 1
For example, if the political group 'Greens/EFA' changed their name from 'Group of Greens/EFA' to 'Global Sustainability Protection and Climate Change Offset', then the change has to be made in more than one entity instance.
/ | pg code | country code | # of seats | pg name | country name | pg chairman / co-chair 1 | co-chair 2 | pop | capital | pop of capital | # of universities in capital |
---|---|---|---|---|---|---|---|---|---|---|---|
Inst 6 | Greens/EFA | BE | 2 | Group of Greens/EFA ⇒ Global Sustainability Protection and Climate Change Offset | Belgium | Monica Frassoni | Daniel Cohn Bendit | 10.6 | Brussels | 1.03 | 14 |
Inst 7 | Greens/EFA | DK | 1 | Group of Greens/EFA ⇒ Global Sustainability Protection and Climate Change Offset | Denmark | Monica Frassoni | Daniel Cohn Bendit | 5.48 | Copenhagen | 0.35 | 2 |
Inst 8 | Greens/EFA | DE | 13 | Group of Greens/EFA ⇒ Global Sustainability Protection and Climate Change Offset | Germany | Monica Frassoni | Daniel Cohn Bendit | 82.27 | Berlin | 3.4 | 28 |
Someone has to enter the same data repeatedly.
Example 2
Another example is that, if the number of universities in Valetta increases, then more than one entity instance has to be updated.
/ | pg code | country code | # of seats | pg name | country name | pg chairman / co-chair 1 | co-chair 2 | pop | capital | pop of capital | # of universities in capital |
---|---|---|---|---|---|---|---|---|---|---|---|
Inst 5 | EPP-ED | MT | 2 | Group of EPP-ED | Malta | Joseph Daul | 0.4 | Valetta | 0.006 | 1 ⇒ 2 | |
Inst 13 | PES | MT | 3 | Socialist Group | Malta | Martin Schulz | 0.4 | Valetta | 0.006 | 1 ⇒ 2 |
Someone has to enter the same data repeatedly.
Redundancy may also lead to Anomalies, as will be explained in the next section.
Redundancy of Data may lead to Anomalies in a Database.
Anomalies can be classified as;
Each type of Anomaly is explained below with an example.
A Deletion Anomaly results when "the deletion of information about one thing of significance" leads to "the deletion of information about another thing of significance".
Example
If the political group 'ALDE/Group of the Alliance of Liberals and Democrats for Europe' ceases to exist, and the Entity Instance # 14 is removed, then we lose all the information about the country of Luxembourg information about its population, its capital, and so on.
/ | pg code | country code | # of seats | pg name | country name | pg chairman / co-chair 1 | co-chair 2 | pop | capital | pop of capital | # of universities in capital |
---|---|---|---|---|---|---|---|---|---|---|---|
Inst 14 | ALDE | LU | 1 | Group of ALDE | Luxembourg | Graham Watson | 0.48 | Luxembourg | 0.076 | 3 |
This is because the only entity instance holding information about Luxembourg is this instance (Instance # 14), and the only entity holding information about countries in our database is this Entity (EP SEATS) we have just one entity in our database. And, we have already seen in the previous section that, in the Entity EP SEATS, there is a very large amount of Redundancy in a total of only fourteen instances.
Deletion Anomaly is caused by unnecessary and unwanted Redundancy.
An Insertion Anomaly occurs when "the information about one thing of significance" CANNOT BE INSERTED, UNLESS "the information about another thing of significance" IS KNOWN.
Example
If a new country enters the EU as a Member, a year or two before the EP elections, then no information about this country can be inserted into the entity EP SEATS,
Why can we NOT INSERT data on this new member country into our Database?
This is because, the new country has no MEPS Member of the Parliaments, belonging to a Political Group yet.
Our Data Model allows an instance to be INSERTED only if, both of the values for the attributes "pg code" and the "country code" are known.
Because these two columns ("pg code" and "country code") together make up the Primary Key, and the Primary Key columns CANNOT BE NULL.
No Elections Yet ⇨ No Political Group ("pg code") Values for the New Country.
/ | pg code | country code | # of seats | pg name | country name | pg chairman / co-chair 1 | co-chair 2 | pop | capital | pop of capital | # of universities in capital |
---|---|---|---|---|---|---|---|---|---|---|---|
Inst 15 | NULL | Country Code of the New Member Country - X | NULL | NULL | New Member Country - X | NULL | NULL | 10 | Capital of the New Member Country - X | 1 | 5 |
Although we have a value for the "country code" component of the Primary Key, we do not have a value for the "pg code" component of the Primary Key.
Hence we CANNOT INSERT this new Instance # 15, into the entity EP SEATS.
This is called Insertion Anomaly.
Insertion Anomaly is also caused by unnecessary and unwanted Redundancy, just like the Deletion Anomaly.
Unnecessary and unwanted Redundancy and Anomalies are NOT APPROPRIATE in Databases.
Redundancy and Anomalies MAY CAUSE Data to Become INCONSISTENT, thus Unusable in the long term.
Entities which Compromise Redundancy and Anomalies are called Entities in Lower Form.
Normalization is a technique which ensures that the Data Model Minimizes Duplication of Data or Redundancy.
Entities in Lower Form are converted into a Higher Normal Form, using the Normalization technique.
Normalization is basicallly achieved by going through Three Stages of Database Design:
We will now investigate the "Three Stages of Normalization" in the following sections.
An Entity is said to be in First Normal Form, or can be labeled 1NF, if the following conditions exist;
1 NF - Condition #1
For example, in the Sample Entity EP SEATS, "pg code" and "country code" are defined as the Composite Primary Key Components.
Hence, the Sample Entity EP SEATS satisfies Condition #1 of 1NF.
1 NF - Condition #2
Another way of saying this, is;
We have already seen in the Dependency section, in the Sample Entity EP SEATS, all the Non-Key Attributes are Functionally Dependent on the Key Attributes.
Hence, the Sample Entity EP SEATS satisfies Condition #2 of 1NF.
1 NF - Condition #3
In the Sample Entity EP SEATS, there are No Repeating Attributes.
Hence, the Sample Entity EP SEATS satisfies Condition #3 of 1NF.
As the Sample Entity EP SEATS satisfies All Three 1NF Conditions, we can say that the entity EP SEATS is in 1NF.
EP SEATS |
---|
pg code |
country code |
# of seats |
pg name |
country name |
pg chairman / co-chair 1 |
co-chair 2 |
pop |
capital |
pop of capital |
# of universities in capital |
We will now look at an Entity which is Not Yet in 1NF.
Our (Fictitious Add-On) Business Narrative said:
"We want to track some basic information on the POLITICAL GROUPs also. For each POLITICAL GROUP, we want to track the political group name, location, address, telephones, e-mails, website information as well as a description of the aim of the POLITICAL GROUP. We would like to track information on the MEMBERS OF THE EUROPEAN PARLIAMENT also. We have to track their names, e-mails, telephones, salaries and so on.
Most of the MEMBERS OF THE EUROPEAN PARLIAMENT(MEPs) have more than one task they perform. For example, an MEP can be a Chair or a Co-Chair or a Vice-President or a Queastor and at the same time, an MEP takes part in several Commissions and Delegations. For example, an MEP can be a Member in one Delegation, and a Chair in another Delegation or a Commission. We need a multiplier for each of these roles. The role multiplier helps us to calculate the total salary of an MEP. We would like to track all these roles.
A POLITICAL GROUP of the EP comprises Members elected in at least one fifth of the EU COUNTRIES and has a minimum of 20 MEMBERS OF THE EUROPEAN PARLIAMENT(MEPs).
An EU COUNTRY may have many MEMBERS OF THE EUROPEAN PARLIAMENT(MEPs) who belong to various POLITICAL GROUPs of the EP.
However, a MEMBER OF THE EUROPEAN PARLIAMENT(MEP) must belong to one and only one POLITICAL GROUP in the European Parliament and an MEP is a citizen of one and only one EU COUNTRY."
Using this Business Narrative, we created the following attributes within the entity POLITICAL GROUP:
"political group id", "political group code", "political group name", "address" ... some other attributes of political group ...
"member 1", "name of member 1", ... some other attributes of member 1, "role 1 of member 1", "role 2 of member 1", "role 3 of member 1", ... , "role n of member 1",
"member 2", "name of member 2", ... some other attributes of member 2, "role 1 of member 2", "role 2 of member 2", "role 3 of member 2", ... , "role n of member 2",
"member 3", "name of member 3", ... some other attributes of member 3, "role 1 of member 3", "role 2 of member 3", "role 3 of member 3", ... , "role n of member 3",
...
...
"member n", "name of member n", ... some other attributes of member n, "role 1 of member n", "role 2 of member n", "role 3 of member n", ... , "role n of member n"
There seems to be a lot of Repeating Attributes in the entity POLITICAL GROUP.
Below are the Repeating Attributes which Represent "members" of the entity POLITICAL GROUP:
"member 1"
"member 2"
"member 3"
...
...
"member n"
Below are the Repeating Attributes which Represent "names of members" of the entity POLITICAL GROUP:
"name of member 1"
"name of member 2"
"name of member 3"
...
...
"name of member n"
Below are the Repeating Attributes which Represent "different roles of member 1" of the entity POLITICAL GROUP:
"role 1 of member 1"
"role 2 of member 1"
"role 3 of member 1"
...
...
"role n of member 1"
Below are the Repeating Attributes which Represent "different roles of member 2" of the entity POLITICAL GROUP:
"role 1 of member 2"
"role 2 of member 2"
"role 3 of member 2"
...
...
"role n of member 2"
...
...
Below are the Repeating Attributes which Represent "different roles of member n" of the entity POLITICAL GROUP:
"role 1 of member n"
"role 2 of member n"
"role 3 of member n"
...
...
"role n of member n"
We can see the Repeating Attributes of the entity POLITICAL GROUP above, and also in the Entity Attributes below.
It is clear that the entity POLITICAL GROUP is NOT YET in 1NF.
It Does Not Satisfy Condition #3 of 1NF.
Entity POLITICAL GROUP is still in Lower Form.
POLITICAL GROUP |
---|
# * political group id |
* political group code |
o political group name |
o address |
o postal code |
* city |
o tel |
o email |
o internet |
o about |
o member 1 |
o name of member 1 |
... some other attributes of member 1 |
o role 1 of member 1 |
o role 2 of member 1 |
... |
o role n of member 1 |
o member 2 |
o name of member 2 |
... some other attributes of member 2 |
o role 1 of member 2 |
o role 2 of member 2 |
... |
o role n of member 2 |
... |
... some other members here |
... |
o member n |
o name of member n |
... some other attributes of member n |
o role 1 of member n |
o role 2 of member n |
... |
o role n of member n |
We will now Convert the entity POLITICAL GROUP into 1NF from the Lower Form it is in.
This is what we must do:
STEP 1: Remove the Repeating Attributes from POLITICAL GROUP
POLITICAL GROUP |
---|
# * political group id |
* political group code |
o political group name |
o address |
o postal code |
* city |
o tel |
o email |
o internet |
o about |
STEP 2: Create a New Entity (MEP) Holding the Repeating Attributes
MEP |
---|
# * member id |
o first name |
* last name |
... |
... some other attributes of member |
... |
o role 1 of member |
o role 2 of member |
o role 3 of member |
... |
... |
o role n of member |
STEP 3: Join MEP to POLITICAL GROUP with a MANY TO ONE Relationship
MANY TO ONE Relationship Between MEP and POLITICAL GROUP
Each MEP MUST belong to One and Only One POLITICAL GROUP.
A POLITICAL GROUP MUST comprise MEPs elected in at least one fifth of the EU COUNTRIES and has a minimum of 20 MEPs.
STEP 4: POLITICAL GROUP is now Converted to 1NF
Summary of the Conversion Process of POLITICAL GROUP from Lower Form to 1NF:
Entity POLITICAL GROUP is now in First Normal Form (1NF):
POLITICAL GROUP |
---|
# * political group id |
* political group code |
o political group name |
o address |
o postal code |
* city |
o tel |
o email |
o internet |
o about |
The entity MEP still has some Repeating Attributes in it.
These Repeating Attributes are the different roles an MEP (Member of the Parliament) may have.
In fact, we have more information on each of these different roles like "id of a role", "code of a role", "title of a role", "salary of a role" and so on ...
Here they are;
"role 1 id", "role 1 code", "role 1 title", "role 1 minimum salary", "role 1 maximum salary", "role 1 multiplier", "role 1 detailed description",
"role 2 id", "role 2 code", "role 2 title", "role 2 minimum salary", "role 2 maximum salary", "role 2 multiplier", "role 2 detailed description",
"role 3 id", "role 3 code", "role 3 title", "role 3 minimum salary", "role 3 maximum salary", "role 3 multiplier", "role 3 detailed description",
...
...
"role n id", "role n code", "role n title", "role n minimum salary", "role n maximum salary", "role n multiplier", "role n detailed description"
There seems to be a lot of Repeating Attributes in the entity MEP.
Below are the Repeating Attributes which represent "role ids" of the entity MEP.
"role 1 id"
"role 2 id"
"role 3 id"
...
...
"role n id"
Below are the Repeating Attributes which represent "role codes" of the entity MEP.
"role 1 code"
"role 2 code"
"role 3 code"
...
...
"role n code"
Below are the Repeating Attributes which represent "role titles" of the entity MEP.
"role 1 title"
"role 2 title"
"role 3 title"
...
...
"role n title"
Below are the Repeating Attributes which represent "minimum salary of roles" of the entity MEP.
"role 1 minimum salary"
"role 2 minimum salary"
"role 3 minimum salary"
...
...
"role n minimum salary"
Below are the Repeating Attributes which represent "maximum salary of roles" of the entity MEP.
"role 1 maximum salary"
"role 2 maximum salary"
"role 3 maximum salary"
...
...
"role n maximum salary"
Below are the Repeating Attributes which represent "role multipliers" of the entity MEP.
"role 1 multiplier"
"role 2 multiplier"
"role 3 multiplier"
...
...
"role n multiplier"
Below are the Repeating Attributes which represent "detailed description of roles" of the entity MEP.
"role 1 detailed description"
"role 2 detailed description"
"role 3 detailed description"
...
...
"role n detailed description"
We can see the Repeating Attributes of the entity MEP above, and also in the Entity Attributes below.
It is clear that the entity MEP is NOT YET in 1NF.
It Does Not Satisfy Condition #3 of 1NF.
Entity MEP is still in Lower Form.
MEP |
---|
# * member id |
o first name |
* last name |
o salary |
o tel |
o internet |
o start date |
o role 1 id |
o role 1 code |
o role 1 title |
o role 1 minimum salary |
o role 1 maximum salary |
o role 1 multiplier |
o role 1 detailed description |
o role 2 id |
o role 2 code |
o role 2 title |
o role 2 minimum salary |
o role 2 maximum salary |
o role 2 multiplier |
o role 2 detailed description |
o role 3 id |
o role 3 code |
o role 3 title |
o role 3 minimum salary |
o role 3 maximum salary |
o role 3 multiplier |
o role 3 detailed description |
... |
... |
o role n id |
o role n code |
o role n title |
o role n minimum salary |
o role n maximum salary |
o role n multiplier |
o role n detailed description |
We will now Convert the entity MEP into 1NF from the Lower Form it is in.
This is what we must do:
STEP 1: Remove the Repeating Attributes from MEP
MEP |
---|
# * member id |
o first name |
* last name |
o salary |
o tel |
o internet |
o start date |
STEP 2: Create a New Entity (ROLE) Holding the Repeating Attributes
ROLE |
---|
# * role id |
* role code |
o role title |
o role minimum salary |
o role maximum salary |
o role multiplier |
o role detailed description |
STEP 3: Join ROLE to MEP with a MANY TO ONE Relationship
MANY TO ONE Relationship Between ROLE and MEP
Each ROLE MUST be held by One and Only One MEP.
Each MEP MUST have One or More ROLES.
STEP 4: MEP is now Converted to 1NF
Summary of the Conversion Process of MEP from Lower Form to 1NF:
Entity MEP is now in First Normal Form (1NF):
MEP |
---|
# * member id |
o first name |
* last name |
o salary |
o tel |
o internet |
o start date |
During the process of Converting entity MEP from Lower Form to 1NF , entity ROLE has also become an entity in First Normal Form 1NF.
ROLE |
---|
# * role id |
* role code |
o role title |
o role minimum salary |
o role maximum salary |
o role multiplier |
o role detailed description |
We now come across a new concept called Composite Entity or Associative Entity.
Let's have a look back at STEP 3: Join ROLE to MEP with a MANY TO ONE Relationship of the previous section.
We have joined ROLE to MEP with a MANY-TO-ONE Relationship.
The Relationships read as follows:
Each ROLE MUST be held by One and Only One MEP.
Each MEP MUST have One or More ROLES.
These Relationships mirror our Business Narrative:
"...
Most of the
MEMBERS OF THE EUROPEAN PARLIAMENT(MEPs)
have
more than one task they perform.
For example, an
MEP
can be a Chair or a
Co-Chair or a
Vice-President
or a Queastor and at the same time,
an MEP can take part in several
Commissions and
Delegations.
For example, an MEP can be
a Member in one Delegation,
and a
Chair in another Delegation or a Commission.
We need a multiplier
for each of these roles.
The
role multiplier
helps us to calculate
the total salary of an MEP.
We would like to track all of these
roles.
..."
It is obvious from our Business Narrative that one role can be held by more than one MEP.
For instance, there will be more than one Co-Chair, or more than one Queastor, or so on among the Member of the Parliaments.
Hence, the Relationship must be MANY-TO-MANY (M:M), and NOT MANY-TO-ONE (M:1).
We now enhance the ER Diagram of ROLE and MEP.
The Relationships now read as follows:
Each ROLE MAY be held by One or More MEPs.
Each MEP MUST have One or More ROLES.
We now have a MANY-TO-MANY Relationship between ROLE and MEP.
MANY-TO-MANY Relationships are difficult to maintain in a database.
To overcome this difficulty, we decompose the M:M (MANY-TO-MANY) Relationship into TWO 1:M (ONE-TO-MANY) Relationships.
This involves creating a New Entity which is known as a Composite Entity or an Associative Entity.
The ER Model of the New Resulting Composite Entity MEP ROLE is shown below.
A Composite Entity is sometimes drawn as a diamond shape within the rectangle.
The Unique Identifier (UID) of this New Composite Entity is a "Combination of its Relationships with the Original Two Entities".
In this case, "member id" and "role id" are the two columns that make up the Unique Identifer or the Composite Primary Key of the New Composite Entity MEP ROLE.
In the section on UIDs, we have already seen that;
Here is the detailed ER Model of the entities MEP, ROLE and MEP ROLE.
This resumes the section on Composite Entity.
An Entity is said to be in Second Normal Form, or can be labeled 2NF, if the following conditions exist;
2 NF - Condition #1
2 NF - Condition #2
As we have already learned, Partial Dependency exists in an entity in which One or More Non-Key Attributes are Dependent on Only One of the Component of the Composite Primary Key.
Question
Answer
We have already seen in the Dependency section, that the Sample Entity EP SEATS has Partial Dependency.
Therefore, EP SEATS is NOT in 2NF.
To Convert the entity EP SEATS from 1NF to 2NF, we have to make sure that the entity is FREE of Partial Dependency .
EP SEATS |
---|
pg code |
country code |
number of seats |
pg name |
country name |
pg chairman / co-chair1 |
co-chair2 |
population |
capital |
population of capital |
number of universities in capital |
We have already seen that "pg name", "pg chairman / co-chair1" and "co-chair2" are Partially Dependent on the Composite Primary Key .
They are Dependent on the "pg code" which is One component of the Composite Primary Key.
EP SEATS |
---|
pg code |
country code |
number of seats |
pg name |
country name |
pg chairman / co-chair1 |
co-chair2 |
population |
capital |
population of capital |
number of universities in capital |
Likewise, attributes "country name" , "population" and "capital" are Dependent on the "country code" which is the Other Component of the Composite Primary Key.
Therefore, they are Partially Dependent on the Composite Primary Key.
EP SEATS |
---|
pg code |
country code |
number of seats |
pg name |
country name |
pg chairman / co-chair1 |
co-chair2 |
population |
capital |
population of capital |
number of universities in capital |
Attributes "population of capital" and "number of universities in capital" are NOT even Partially Dependent on the Primary Key.
These Attributes are Dependent on the attribute "capital", which is itself Dependent on the "country code".
Therefore, attributes "population of capital" and "number of universities in capital" are Transitively Dependent on "country code".
EP SEATS |
---|
pg code |
country code |
number of seats |
pg name |
country name |
pg chairman / co-chair1 |
co-chair2 |
population |
capital |
population of capital |
number of universities in capital |
We want to end up with Entities where NO Partial Dependency exists.
This is achieved by Decomposing the EP SEATS which is in 1NF, into Three Entities in 2NF.
EP SEATS 1 |
---|
pg code |
country code |
number of seats |
EP SEATS 2 |
---|
pg code |
pg name |
pg chairman / co-chair1 |
co-chair2 |
EP SEATS 3 |
---|
country code |
country name |
population |
capital |
population of capital |
number of universities in capital |
We Decomposed EP SEATS into Three Entities;
No Partial Dependency exists in any of the Three Entities.
Therefore, we can say that they are in Second Normal Form or they are in 2NF.
We have already seen in the section Conversion from Lower Form to 1NF that the entities POLITICAL GROUP, MEP and ROLE are in First Normal Form 1NF .
All of their NON-KEY Attributes are Dependent on the Primary Key.
As their Primary Keys are made up of only One Attribute, there can be NO Partial Dependency.
Hence, the entities POLITICAL GROUP, MEP and ROLE are also in Second Normal Form 2NF.
POLITICAL GROUP |
---|
# * political group id |
* political group code |
o political group name |
o address |
o postal code |
* city |
o tel |
o email |
o internet |
o about |
MEP |
---|
# * member id |
o first name |
* last name |
o salary |
o tel |
o internet |
o start date |
ROLE |
---|
# * role id |
* role code |
o role title |
o role minimum salary |
o role maximum salary |
o role multiplier |
o role detailed description |
An Entity is said to be in Third Normal Form, or can be labeled 3NF, if the following conditions exist;
3 NF - Condition #1
3 NF - Condition #2
An Entity that Has Transitive Dependency is NOT in Third Normal Form but has to be Decomposed Further to achieve 3NF.
However, an Entity in 2NF that Does NOT Contain any Transitive Dependencies among its attributes is already in 3NF.
Entities EP SEATS 1 and EP SEATS 2;
Therefore, the entities EP SEATS 1 and EP SEATS 2 are already in Third Normal Form 3NF.
EP SEATS 1 |
---|
pg code |
country code |
number of seats |
EP SEATS 2 |
---|
pg code |
pg name |
pg chairman / co-chair1 |
co-chair2 |
The entity EP SEATS 3 is also in Second Normal Form 2NF.
However, EP SEATS 3 has Transitive Dependency:
EP SEATS 3 |
---|
country code |
country name |
population |
capital |
population of capital |
number of universities in capital |
Attributes "population of capital" and "number of universities in capital" are Dependent on the Non-Key Attribute "capital".
EP SEATS 3 needs to be converted into 3NF.
This is what we do to convert EP SEATS 3 into 3NF:
EP SEATS 3 and EP SEATS 4 are now in 3NF.
EP SEATS 3 |
---|
country code |
country name |
population |
capital |
EP SEATS 4 |
---|
capital |
population of capital |
number of universities in capital |
We have already seen in the previous section "Conversion from 1NF to 2NF" that the entities POLITICAL GROUP, MEP and ROLE are in Second Normal Form 2NF.
They have NO Transitive Dependency either.
Hence, the entities POLITICAL GROUP, MEP and ROLE are in 3NF.
1. Entities
2. Relationships
3. Attributes
4. Unique Identifier UID
Normalized Model
"Whoever wants to reach a distant goal must take many small steps."
- Anonymous
Using the processes to create an ER Model and Normalization, we finalize our ER Model.
Important Note
This is a partial ER Model of the European Union which consists of the European Parliament and is sufficient enough for the purposes of this text, which is to teach the Elementary Basics of the SQL Language.
Important Note
The names of Political Groups, MEPs and their Roles are taken from the website of the European Parliament https://www.europarl.europa.eu/portal/en and from several publications of the EU, which are listed in the References section, and whose reproduction is authorized, provided the source is acknowledged.
Therefore data related to these are true to reality.
Important Note
However, the concept of Role Multipliers of the MEPs are completely fictitious.
The data for the attributes of 'salary' and 'role multiplier' are made-up. These attributes are used later on in explaining some SQL Concepts.
Please Note: