Anda di halaman 1dari 65

What is DBMS ?

A DBMS is a collection of programs that


manages the database structure and controls
access to the data stored in the database.
DATA MODEL
A data model is a plan for building a database.
The model represents data conceptually, the way the
user sees it, rather than how computers store it.
Data models focus on required data elements and
associations; most often they are expressed
graphically using entity-relationship diagrams.
Data models are also used in describing a database's
overall structure -- e.g., a relational or hierarchical
data model.
Data Modeling With Entity-Relationship Diagrams

rectangles represent entities, diamonds are relationships, and


ellipses are attributes of entities.
Logical data models (LDMs)
• LDMs are used to explore the domain concepts, and
their relationships, of your problem domain.
•LDMs depict the logical entity types, typically
referred to simply as entity types, the data attributes
describing those entities, and the relationships
between the entities.
Physical data models (PDMs).
PDMs are used to design the internal schema of a
database, depicting the data tables, the data columns
of those tables, and the relationships between the
tables.
CARDINALITY

Note that many employees can share the same job type
Cardinality is the term used to express this type of
relationship.
Cardinality describes the numeric relationships between
occurrences of entities in the primary/foreign key table.
It may be many to many or one to one.
Data integrity
data integrity means that the data values in the
database are correct and consistent.
Data integrity means, in part, that you can correctly
and consistently navigate and manipulate the tables in
the database.
Data integrity is enforced in the relational model by
entity and referential integrity rules.
Entity Integrity

•The entity integrity rule states that for every instance


of an entity, the value of the primary key must exist,
be unique, and cannot be null.
•Without entity integrity, the primary key could not
fulfill its role of uniquely identifying each instance of
an entity.

Eg: EMPNO column is primary key in EMP table


DEPTNO column is primary key in DEPT table
Referential Integrity
•The referential integrity rule states that if a relational
table has a foreign key, then every value of the foreign
key must either be null or match the values in the
relational table in which that foreign key is a primary
key.
•Referential integrity ensures that we can correctly
navigate between related entities
Eg : DEPTNO column in EMP is FOREIGN KEY
with reference to DEPTNO column in DEPT which is
a PRIMARY KEY
Foreign key….
A foreign key creates a hierarchical relationship
between two associated entities.
The entity containing the foreign key is the child, or
dependent, and the table containing the primary key
from which the foreign key values are obtained is the
parent.
In order to maintain referential integrity between the
parent and child as data is inserted or deleted from the
database certain insert and delete rules are to be
considered.
E F CODD's RULES
Codd presented twelve rules that a database must obey
if it is to be considered truly relational.
1. The information rule. All information in a relational
database is represented explicitly at the logical level
and in exactly one way  by values in tables.
Rule 1 is basically the informal definition of a
relational database.
2. Guaranteed access rule. Each and every datum
(atomic value) in a relational database is guaranteed to
be logically accessible by resorting to a combination
of table name, primary key value, and column name.
Rule 2 stresses the importance of primary keys for
locating data in the database. The table name locates
the correct table, the column name finds the correct
column, and the primary key value finds the row
containing an individual data item of interest.
3. Systematic treatment of null values. Null values are
supported in a fully relational DBMS for representing
missing information and inapplicable information in a
systematic way, independent of the data type.
Rule 3 requires support for missing data through
NULL values.
4. Dynamic online catalog based on the relational
model. The database description is represented at the
logical level in the same way as ordinary data, so that
authorized users can apply the same relational
language to its interrogation as they apply to the
regular data.
Rule 4 requires that a relational database be self-describing. In
other words, the database must contain certain system tables
whose columns describe the structure of the database itself.
5. Comprehensive data sublanguage rule. A relational system
may support several languages and various modes of terminal
use (for example, the fill-in-the-blanks mode). However, there
must be at least one language whose statements are
expressible, per some well-defined syntax, as character strings,
and that is comprehensive in supporting all of the following
items:
•Data definition
•View definition
•Data manipulation (interactive and by program)
•Integrity constraints
•Authorization
•Transaction boundaries (begin, commit, and rollback)
Rule 5 mandates using a relational database language, such as
SQL, although SQL is not specifically required. The language
must be able to support all the central functions of a DBMS --
creating a database, retrieving and entering data, implementing
database security, and so on.
6. View updating rule. All views that are theoretically
updateable are also updateable by the system.
Rule 6 deals with views, which are virtual tables used to give
various users of a database different views of its structure. It is
one of the most challenging rules to implement in practice,
and no commercial product fully satisfies it today.
7. High-level insert, update, and delete. The capability of
handling a base relation or a derived relation as a single
operand applies not only to the retrieval of data but also to the
insertion, update, and deletion of data.
Rule 7 stresses the set-oriented nature of a relational database.
It requires that rows be treated as sets in insert, delete, and
update operations. The rule is designed to prohibit
implementations that only support row-at-a-time, navigational
modification of the database.
8. Physical data independence. Application programs and
terminal activities remain logically unimpaired whenever any
changes are made in either storage representations or access
methods.
9. Logical data independence. Application programs and
terminal activities remain logically unimpaired when
information preserving changes of any kind that theoretically
permit unimpairment are made to the base tables.
Rule 8 and Rule 9 insulate the user or application program
from the low-level implementation of the database. They
specify that specific access or storage techniques used by the
DBMS, and even changes to the structure of the tables in the
database, should not affect the user's ability to work with the
data.
10. Integrity independence. Integrity constraints specific to a
particular relational database must be definable in the
relational data sublanguage and storable in the catalog, not in
the application programs.
Rule 10 says that the database language should support
integrity constraints that restrict the data that can be entered
into the database and the database modifications that can be
made. This is another of the rules that is not support in most
commercial DBMS products.
11. Distribution independence. A relational DBMS has
distribution independence.
Rules 11 says that the database language must be able to
manipulate distributed data location on other computer
systems.
12. Nonsubversion rule. If a relational system has a low-level
(single record at a time) language, that low level cannot be
used to subvert or bypass the integrity rules and constraints
expressed in the higher level relational language (multiple
records at a time).
Rule 12 prevents "other paths" into the database that might
subvert the relational structure and integrity.
RELATIONAL TERMINOLOGY
Formal Name Common Name Also Known As
Relation Table Entity
Tuple Row Record
Attribute Column Field
•A Primary Key is one or more columns whose values
uniquely identify a row in a table
•A Candidate Key is one or more columns whose
values could be used to uniquely identify a row in a
table. The Primary Key is chosen among a table's
Candidate Keys.
•A Domain is the set of all possible values of an attribute
NORMALIZATION
Normalization is the process of decomposing and
arranging the attributes in a schema, which results in a
set of tables with very simple structures.
The purpose of normalization is to make tables as
simple as possible.
There are different types of normal forms i.e., First
normal form, Second normal form, Third normal
form, Forth normal form, Boyce/Codd Normal Form
etc.,
FIRST NORMAL FORM
Reduce entities to first normal form (1NF) by removing
repeating or multivalued attributes to another, child entity
OrderNo Item1 Qty1 Price1 Item2 Qty2 Price2
245 PN768 1 $35 PN656 3 $15
Company's order system

If the order items were implemented as multiple columns in


the Orders table, the database would not be 1NF
To make this first normal form, we would have to create
a child entity of Orders (Order Items) where we would
store the information about the items on the order. Each
order could then have multiple Order Items related to it.
OrderNo
245

OrderNo Item Qty Price


245 PN768 1 $35
245 PN656 3 $15
Second Normal Form
Reduce first normal form entities to second normal form
(2NF) by removing attributes that are not dependent on
the whole primary key.
•The purpose here is to make sure that each column is
defined in the correct table.
Consider Order Item table with Customer reference
Orderno Itemno Customer Item Qty Price
245 1 SteelCo PN768 1 $35
245 2 SteelCo PN656 3 $15
246 1 Acme Corp PN371 1 $2.99
246 2 Acme Corp PN015 7 $5
•Assume Order Number and Item Number as the
Primary Key
•The Customer reference becomes repeated in the table
because it is only dependent on a portion of the Primary
Key (Order Number).
•Therefore, it is defined as an attribute of the wrong
entity.
•Customer reference should be in the Orders table, not
the Order Items table.
Orderno Customer
245 SteelCo
246 Acme Corp

Orderno Itemno Item Qty Price


245 1 PN768 1 $35
245 2 PN656 3 $15
246 1 PN371 1 $2.99
246 2 PN015 7 $5
Third Normal Form
Reduce second normal form entities to third normal form
(3NF) by removing attributes that depend on other,
nonkey attributes (other than alternative keys).
This basically means that we shouldn't store any data
that can either be derived from other columns or belong
to another table.

Orderno Customer Address City


245 Acme Corp Works Blvd Vinings
246 SteelCo North Drive South Bend
247 Acme Corp Works Blvd Vinings
Orderno Customer Address City
245 Acme Corp Works Blvd Vinings
246 SteelCo North Drive South Bend
247 Acme Corp Works Blvd Vinings

Orderno Customer
245 Acme Corp
246 SteelCo
247 Acme Corp

Customer Address City


Acme Corp Works Blvd Vinings
SteelCo North Drive South Bend
Exercise
Normalize following table
Exercise
Normalize following table
Solution

Anda mungkin juga menyukai