2. Entity Relationship – E R
Data Model entity relationship consists of objects
of a group called the entity and the relationship
between entities
Data Model E R is divided into 3 basic concept
that is association association entity, relationship
and the attributes
3. Entity association and entity
an entity is an object basis or individuals who
represents a real one hardly and can be
distinguished from the objects of objects that
another
entity has a nature, and the value of some of
the is a unique can identify the entity
4. Entity
as an example : each student in a college was
the entity and NIM uniquely identity can be a
college student
5. Entity set
entity Entity a group that has a type that period and is in
scope which forms a complex entity
as an example a crowd of people who became a
student at a college, can be defined as association
an entity entity college students. possess attributes .
attributes the properties - qualities or property that entity
. attributes this makes the difference between between
entities that one with another entity
6. For example entity students have attributes nim,
the name, address and date of birth
Students
nim name
address
Date of birth
7. Attributes in E-R
characterized in some types:
the attributes simple and the composite
attributes high-single and many
attributes null
attributes derivative
8. Relationship
A relation is defined as a set of tuples that have the same attributes.
A tuple usually represents an object and information about that
object. Objects are typically physical objects or concepts. A relation
is usually described as a table, which is organized
into rows and columns. All the data referenced by an attribute are in
the same domain and conform to the same constraints.
10. Representations of a Relationship
Married
Man
Married
Woman
IS
MARRIED
TO
(a) The IS MARRIED TO relationship
Alvi ----------------------------------- Kurnia
Rizal ----------------------------------- Aulia
Akhmadi ----------------------------------- Meris
(b) Some instances of IS MARRIED TO
11. Cardinality
The degree of relationship (also known as cardinality) is the
number of occurrences in one entity which are associated (or
linked) to the number of occurrences in another.
There are three degrees of relationship, known as:
One-to-one (1:1)
One-to-many (1:M)
Many-to-many (M:N)
12. One to One
This is where one occurrence of an entity relates to only one occurrence in
another entity.
A one-to-one relationship rarely exists in practice, but it can. However, you
may consider combining them into one entity.
For example, an employee is allocated a company car, which can only be
driven by that employee.
Therefore, there is a one-to-one relationship between employee and company car.
13. One to Many
Is where one occurrence in an entity relates to many occurrences in
another entity.
For example, taking the employee and department entities shown on
the previous page, an employee works in one department but a
department has many employees.
Therefore, there is a one-to-many relationship between department
and employee.
14. Many to Many
This is where many occurrences in an entity relate to many occurrences in
another entity.
The normalization process discussed earlier would prevent any such
relationships but the definition is included here for completeness.
As with one-to-one relationships, many-to-many relationships rarely exist.
Normally they occur because an entity has been missed.
For example, an employee may work on several projects at the same time
and a project has a team of many employees.
Therefore, there is a many-to-many relationship between employee and
project.
15. Optional Relationships
A relationship may also be optional. Either end of the relationship can include zero occurrences as an
option. This is defined by the business rules of the system being implemented.Taking the three
examples above, the business rules may allow for the following.
Not all employees are allocated a company car.
A car is defined as a pool car and not allocated to a specific employee.
A new department is created but, as yet, there are no employees working within it.
A new project is defined but as yet the team has not been established.
A new employee starts within the company but, as yet, is not assigned to a project.
Taking the first business rule, graphically this can be shown as:
The circle (O) represents optionality. This will be discussed further later in this section.
16. Recursive Relationships
In the examples above, a relationship has always been between occurrences in two
different entities. However, it is possible for the same entity to participate in the
relationship. This is termed a recursive relationship.
Let us take the example of an employee who is also a manager. But a manager is also
an employee, whose details will be held in the employee entity. To implement this a
foreign key of the employee's manager number would be held in each employee
record.
Employee entity
Employee no
Employee surname
Employee forename
Employee DOB
Employee NI number
Manager no * (this is the employee no of the employee's manager)
Graphically, this can be shown as:
19. Data Types in The Database
The data type is always used to determine the data type of a field in
a table. There are ten types of data provided in the database.
AutoNumber: Displaying numbers automatically starting from the
number 1, followed by the number 2, 3, 4, and seteusnya.
Currency: Data Memnampung digit, minus sign, and the sign of the
decimal point with 15 digits to the left of the sign of the decimal
point and 4 digits to the right of the decimal point.
Date / Time: Accommodating the data date, time, and year
starting from 100 up to 9999.
Hyperlink: Accommodating the data colored text, underlined, and
graphics.
20. Lookup Wizard: menampilakan a data type of many
types of data are taken from tables and queries.
Memo: Accommodating text data (letters, numbers,
punctuation, and symbols chart) as much as 65,535
characters. This type can not be indexed
Number: Accommodating digit, minus sign, and a
decimal point. This type has 5 bilanngan size and
number of digits.
OLE object: Holds photo / graphic images, sound and
video recordings, and spreadsheets. The maximum
capacity of this type of data is 1 Gb. This type can not
be indexed.
21. Text: Accommodating text data (letters, numbers, and
symbols chart) as many as 255 characters. Standard
characters inserted by 50 characters.
Yes / No: Holds one of the two available Yes / No,
True / False, and On / Off.
22. The following data types are supported by MySQL are drawn from the MySQL
documentation. Type - This data type is given in the form of ready-written in the
syntax of MySQL syntax, for example, the Create Table.
In these data types are some of the attributes that have the following meanings:
M, indicates the maximum character width. The maximum value of M is 255.
D, indicates the number of decimal places. The maximum value of D is 30, but is
limited by the value of M, which can not be larger than the M-2.
Marked attributes [and] means their use is optional.
If the attribute is included ZEROFILL, MySQL will automatically add the
UNSIGNED attribute.
UNSIGNED is a number without a sign in front of it (eg, a negative sign).
23. Types of keys in database
1. Primary key
The primary key is an attribute or a set of attributes that are not only minimal uniquely define a specific incident but also
can represent each occurrence of an event.
Field value must be the primary key:
- Unique or may not double
- Not be Null (empty, not known, can not be determined)
- Key is more natural to be a reference
- Database without any data being foreign. Each table can have one or more candidate keys.
- Key may consist of more than one Key field consisting of more than one column is called Composite Key
2. Foreign Key
is a set of attribute or set of attributes as the key link and complete the second table of the relationship (relationship) on the
primary key that shows main key.
If a primary key to the table are connected / other entity, then the existence of a primary key in the entity referred to as a
foreign key.
24. 3. Candidat keys (candidate keys / key candidates)
is an attribute or a minimum set of attributes that uniquely identifies only for a specific
occurrence of the entity.
Candidate key must satisfy the following requirements:
Unique Identifier, for each row / tuple must be unique candidate key can be an identifier.
That is, every non-candidate key attribute is functionally dependent on the candidate.
Non-Redundancy, no candidate key duplication to be a unique identifier, which can not be
done on the elimination of candidate key which does not damage the unique identifier
properties.
4. Composite Key
In database design, a composite key is a key that consists of two or more attributes that
uniquely identify an entity occurrence. Each of the key attributes that make up the
compound is a simple key in its own right.
compositing at least one key attributes that make up the composite is not a simple key.
5. Alternative Key is a candidate key which is not selected as the primary key.
6. Secondary key is an attribute or a combination that is used only for the purpose of data
retrieval.
25. Normalization
Database normalization is a systematic approach to
minimize data redundancy in a database so that the
database can work optimally. If you are a database
administrator when there is something in the database
such as performance degradation, you may be asked
whether the database has been normalized?
26. The purpose of the Database
Normalization
The goal of database normalization is to eliminate and reduce data
redundancy and the second goal is to ensure data dependencies (data are on
the table right).
If the data in the database has not been normalized, there will be 3 chances to
be detrimental to the overall system.
INSERT Anomaly: Situations where not allow to enter multiple types of data
directly in the database.
Anomaly DELETE: Deletion of data that is not as expected, meaning that the
data should not be deleted may also be deleted.
UPDATE Anomaly: Situations where the value is converted cause database
inconsistencies, in the sense that the data is not modified in accordance with
the commanded or desired.
27. Database Normalization
Database normalization is composed of many forms, in
science there are at least 9 database normalization
existing form is 1NF, 2NF, 3NF, EKNF, BCNF, 4NF, 5NF,
DKNF, and 6NF. However, in practice in the form of
normalization is the industry's most commonly used
about 5 forms.
28. Normal Form
Data were recorded and entered in a table in raw form is very possible that
the data inconsistencies and anomalies
Examples of Normal Form
In this form there are some important characteristic features, the first is
going to happen anomaly in the insert, update, and delete. This causes
some functions in SQL DML can not run properly. For example if you want to
remove the title of the book publisher, the data will be lost as well if you
want to delete the borrower, then the data publishers and books that
should not be deleted will go missing.
29. First Normal Form (1NF)
The first normal form or 1NF requires several conditions in
a database, the following is a function of the first normal
form.
Eliminate duplicate columns from the same table.
Create separate tables for each group of related data
and identify each row with a unique column (the
primary key).
31. In essence this form of normalization 1NF classifying
multiple data types or groups of similar data so that the
data can be separated so that anomalies can be
overcome.
Examples of is when we want to delete, update, or add
data to the borrower, then we do not intersect with the
data books or data publisher. So that the inconsistency
of data can start at guard.
32. Second normal form (2NF)
Conditions for applying the second form is the
normalization of data has been created in 1NF, the
following are some of the functions of 2NF normalization.
Removing some subset of the existing data in the table
and put them in a separate table.
Creating new relationships between tables and the old
table by creating a foreign key.
There are no attributes in the table are functionally
dependent on the candidate keys of the table.
33. Examples of database normalization
form 2NF
Above example, we use a table that is transaction table, in
essence, this is the second bentu should not be any field
related to other functional fields. Examples of Book Title
hanging with id_Buku so in the form 2NF titles can be
removed because it has its own master table.
34. Third Normal Form (3NF)
Database in the form of 3NF normalization aims to remove
all the attributes or fields that are not associated with the
primary key. Thus there is no transitive dependencies on
each candidate key. Terms of the third normal form or 3NF
is:
Meet all the requirements of the second normal form.
Removing columns that are not dependent on the
primary key.
35. Examples of Forms 3NF Database
Normalization
Not all cases or tables can be adjusted with the
various forms of this normalization, for example 3NF
we will take the example of table orders.
36. In the first table above, if all the columns are fully
dependent on the primary key? of course not, it's just that
there is one field that is dependent on the total price and
quantity, can be generated by multiplying the total price
and quantity. Form of 3NF in the table above can be done
by removing the total field.
37. Database Normalization Function
In science databases or database, normalization is used to avoid
the occurrence of various data anomalies and consistency of data.
This is a general database functions. In some cases this
normalization is very important to the performance of the database
and ensure that the data in the database is secure and no error
occurs if it gets particularly DML SQL commands that update, insert,
and delete.
Please note in some cases database normalization sometimes be
transformed to the form denormalisasi, especially for data that has
a large and swollen. Denormalisasi is intended to improve
performance by putting multiple fields into one table so easily in
drag. Denormalisasi is often used to attract large amounts of data
from the database.