Professional Documents
Culture Documents
A collection of data or information about realworld entities such as objects or events. A collection of related records held over a period of time in a computer-readable form. A shared, integrated, computer structure that stores a collection of Data, that is raw facts of interest to the user.
Advanced DBMS
Applications of Databases
the preferred method of storage for large multi-user applications, where coordination between many users is needed information systems. many electronic mail programs and personal organizers are based on standard database technology. Software database drivers are available for most database platforms so that application software can use a common Application Programming Interface to retrieve the information stored in a database.
Advanced DBMS
What is a DBMS?
A computer software designed for the purpose of managing databases. A software program that manages the storage of and access to data in databases. is a complex set of software programs that controls the organization, storage, management, and retrieval of data in a database
Monday, September 03, 2012 Advanced DBMS 3
Role/Advantages of DBMS
Improved data sharing Better data integration Minimized data inconsistency Improved data access Improved decision making Increase end-user productivity
Advanced DBMS
Typical DBMSs
Apache Derby (Sun Java DB) BerkeleyDB dBase IBM DB2 Informix Ingres Microsoft Access Microsoft SQL Server (derived from Sybase) MySQL Oracle Database Paradox (database) PostgreSQL Sybase Visual FoxPro
Advanced DBMS 5
Components of a DBMS
Modeling language
defines the schema of each database hosted in the DBMS, according to the DBMS data model.
Advanced DBMS
Components of a DBMS
Database query language
allow users to interactively interrogate the database, analyze its data and update it according to the user privileges on data
Transaction mechanism
would guarantee the ACID properties, in order to ensure data integrity, despite concurrent user access and faults
Monday, September 03, 2012 Advanced DBMS 7
Advanced DBMS
Advanced DBMS
10
Advanced DBMS
11
Conceptual Level
The community view of the database Describes what is stored in the DB & the relationships among the data
Internal Level
The physical representation of the database in the computer Describes how the data is stored in the DB
Monday, September 03, 2012 Advanced DBMS 12
Data Independence
Upper levels are unaffected by changes to lower levels Logical Data Independence
Being able to make changes on the conceptual schema without any on the external schema.
Classification/Types of DBMSs
Accdg. to Data model
Hierarchical, network, relational
Accdg. to # of users
Single-user, multi-user
Accdg. to # of sites
Centralized, distributed
Accdg. to purpose
General, special purpose
Monday, September 03, 2012 Advanced DBMS 14
Database Design
Refers to the activities that focus on the design of the database structure that will be used to store and manage end-user data What is a good database?
Meets all the requirements Must be designed carefully A well-designed database facilitates data management and generates accurate and valuable information.
Monday, September 03, 2012 Advanced DBMS 15
Data Model
An abstraction of a more complex real-world object or event Help you understand the complexities of realworld environment Represents data structures and their characteristics, relations, constraints, and transformations Facilitates interaction among the designer, the applications programmer, and the end-user.
Monday, September 03, 2012 Advanced DBMS 16
Data Models
Defines a method for data organization It specifies relationships and integrity rules in databases DBMSs can be based on a data model
Hierarchical Network Relational
Advanced DBMS
17
Hierarchical Model
data is organized into a tree-like structure Every entity has one to two immediate neighbors superior or subordinate. Restrictions:
Branches can only diverge & are not allowed to converge.
A child element can be related to only one parent.
Prevents any entity from being related to any entity more than one level up the hierarchy.
Monday, September 03, 2012 Advanced DBMS 18
Automobile
Aerospace
Sales
MIS
Marketing
Research
HR
MIS
Ann Lane
Joe Smith
Bob Lee
Laura Kline
Advanced DBMS
19
Network Model
Derived from the hierarchical model Basic structure of superior and subordinate retained Difference:
Allows child entity to have more than one parent Allows a child to be connected directly to a grandparent element
Advanced DBMS
20
Automobile
Aerospace
Sales
MIS
Marketing
Research
HR
MIS
Ann Lane
Joe Smith
Bob Lee
Laura Kline
Advanced DBMS
21
Relational Model
Rooted in 2 branches of mathematics:
Set theory properties of sets Predicate calculus mathematical proposition
permits the database designer to create a consistent, logical representation of information All data about entities are contained in tables Any table can be reference other tables through the use of keys & relationships
Monday, September 03, 2012 Advanced DBMS 22
Relational Database
originally defined and coined by E.F. Codd a database that conforms to the relational model, and refers to a database's data and schema (the database's structure of how that data is arranged). a set of relations or a database built in an RDBMS (Relational DBMS) a relational database is a collection of relations (frequently called tables)
Monday, September 03, 2012 Advanced DBMS 24
Relational DBMS
a system that manages data using the relational model the term "RDBMS" is inaccurately used as a generic label for the relational database concept examples: MySQL, PostgreSQL, Oracle, Microsoft SQL Server, Ingres etc.
Advanced DBMS
25
Advanced DBMS
26
Relation
a set of tuples (record) that all have the same attributes
Attribute property of an entity/relationship
is usually represented by a table, which is data organized in rows & columns all of the data stored in a column should be in the same domain
Domain-set of possible values for a given attribute
Monday, September 03, 2012 Advanced DBMS 27
Relation: An Example
SSN LastName FirstName Address Ola Tove Kari Timoteivn 10 Borgvn 23 Storgt 20 City Sandnes Sandnes Stavanger 123456 Hansen 789012 Svendson 345678 Pettersen
Advanced DBMS
28
Keys
a kind of constraint which requires that the object, or critical information about the object, isn't duplicated A set of one or more attribute
Candidate key-all attributes with unique value Primary key-chosen key Simple key-only one attribute Composite key-made up of two or more attributes Foreign key-an attribute used to reference a primary key in a another table/relation
Monday, September 03, 2012 Advanced DBMS 29
Key: An Example
Key: primary key
SSN LastName FirstName Address City
123456 Hansen
789012 Svendson 345678 Pettersen
Ola
Tove Kari
Timoteivn 10
Borgvn 23 Storgt 20
Sandnes
Sandnes Stavanger
Advanced DBMS
30
Relationships
An association of entities where the association includes one entity from each participating entity type Example:
borrower employee product
Monday, September 03, 2012
Borrows/returns
material department
belongs/employs
sold/bought
customer
Advanced DBMS
31
ADBS
32
ADBS
33
Entities
The basic object of the real world Defined by a set of attributes (properties) Uniquely identified by a primary key Classified with similar entities under one set Considered an instance of a given entity type Tangible or intangible
ADBS
36
Entities: An Example
Entity Type: Employee
Attributes
SSN
LastName
FirstName Address
City
123456 Hansen
789012 Svendson 345678 Pettersen
Ola
Tove Kari
Timoteivn 10
Borgvn 23 Storgt 20
Sandnes
Sandnes Stavanger
Tuples/records/entity set
ADBS
37
Entity Types
Weak Entity type
An entity type that is existence-dependent on some other entity type (do not have their own keys) Example: employee dependents
ADBS
38
Attributes
pieces of information ABOUT entities analysis must of course identify those which are actually relevant to the proposed application give rise to recorded items of data in the database
ADBS
39
Characteristics of an Attribute
attribute name. the domain from which attribute values are taken.
Set of allowable values of an attribute
whether the attribute is part of the entity identifier. whether it is permanent or time-varying. whether it is required or optional for the entity.
Monday, September 03, 2012 ADBS 40
Types of Attributes
Simple single component with an independent existence Composite multiple components, each with an independent existence Single-valued holds a single value for a single entity Multi-valued holds multiple value for a single entity Derived attribute value is taken from a related attribute
Monday, September 03, 2012 ADBS 41
Examples
Simple & single-valued Ex. gender, civil status
Ex. Phone #
Ex. name
Ex. address
ADBS
42
Relationships
An association of entities where the association includes one entity from each participating entity type should be named by a word or phrase which explains its function
ADBS
43
Relationships: Examples
borrower employee product
Borrows/returns
belongs/employs
sold/bought
relationships
ADBS
44
Degree of a Relationship
The degree indicates the # of associated entities
Unary Relationship
Same entity participates more than one in different roles
Binary Relationship
Two different entities participate in the relationship
Ternary Relationship
Three different entities participate in the relationship
Monday, September 03, 2012 ADBS 45
Examples
Unary Relationship Binary Relationship
STAFF
supervises
OWNER
owns
PROPERTY
STAFF
Ternary Relationship
RENTER
Sets up
INTERVIEW
ADBS
46
Mapping Cardinality
Expresses the number of entities to which another entity can be associated via a relationship set The number of participating entities in a relationship
ONE-TO-ONE, e.g. Building - Location, ONE-TO-MANY, e.g. hospital - patient, MANY-TO-MANY, e.g. Author - Book. RECURSIVE, e.g. Manager - Employee.
Monday, September 03, 2012 ADBS 47
Entity Participation
A relationship may be required/mandatory or optional for either participant e.g. a piece of property must be owned by a person but not all persons need to own a piece of property.
ADBS
48
Sample Notations
ADBS
49
ADBS
50
A Complete ER Diagram
deptid deptname
works for empid
DEPARTMENT
name
EMPLOYEE
address
manages
PROJECT
projname
hours
ADBS
51
Exercise
FastFlight Airlines is a small air carrier operating in three northeastern states. FastFlight is in the process of computerizing its passenger reservation system. The following data items have been identified: reservation code, flight number, flight date, origin, destination, departure time, arrival time, passenger name, seat number, reservation agent number and reservation agent name. For example, flight number 303, which is scheduled every Tuesday and Thursday, leaves Augusta, Maine, at 9:23am and arrives in Nashua, New Hampshire at 10:17am. You can assume that the FastFlight reservation system will detect automatically whether empty seats are available. Draw the Entity Relationship Diagram for this system.
ADBS
52
Transformation
Involves the transformation of the ER diagram to a complete database scheme Entity set in the ER model become tables in a relational database The relationships become the source of foreign keys that integrate the resulting table together Based on the mapping cardinalities & entity participation of the relationship
9/3/2012 ADBS
Given
Let:
E1 and E2 be entity sets R be a relationship that associates E1 & E2
ER Diagram:
attrR pkE1 attrE1 attrE2 pkE2
E1
E2
9/3/2012
ADBS
Rule 1
many-to-many regardless of entity participation attrR
pkE1 attrE1
attrE2
pkE2
E1
E1(pkE1,attrE1) E2(pkE2,attrE2) R(pkE1,pkE2,attrR)
9/3/2012
E2
ADBS
Rule 2
One-to-many, mandatory on the many side regardless of entity participation on the 1 attrR side attrE2
pkE1 attrE1
pkE2
E1
E2
E1(pkE1,attrE1,pkE2,attrR) E2(pkE2,attrE2)
ADBS
9/3/2012
Rule 3
One-to-many, optional on the many side regardless of entity participation on the 1 side attrR
pkE1 attrE1 attrE2
pkE2
E1
E1(pkE1,attrE1)
E2(pkE2,attrE2) R(pkE1,pkE2,attrR)
9/3/2012
E2
ADBS
Rule 4
One-to-one, mandatory on both sides
attrR pkE1 attrE1 attrE2 pkE2
E1
E2
E1(pkE1,attrE1,pkE2,attrR)
E1(pkE1,attrE1) or E2(pkE2,attrE2,pkE1,attrR)
E2(pkE2,attrE2)
9/3/2012
ADBS
Rule 5
One-to-one, mandatory on one side
attrR pkE1 attrE1 attrE2 pkE2
E1
E2
E1(pkE1,attrE1,pkE2,attrR) E2(pkE2,attrE2)
9/3/2012
ADBS
Rule 6
Optional on both sides
attrR pkE1 attrE1 attrE2 pkE2
E1
E2
9/3/2012
ADBS
E1
E2
E1(pkE1,attrE1,attrR) E2(pkE2,attrE2,pkE1)
9/3/2012
ADBS
resides
9/3/2012
ADBS
DEPARTMENT
name
EMPLOYEE
address
manages
PROJECT
projname hours
9/3/2012
ADBS
EMPLOYEE
address hours bdate
works on
PROJECT
projname
Next
empid name deptid works for
EMPLOYEE
address
DEPARTMENT
deptname
bdate
EMPLOYEE(empid,name,address,bdate,deptid) DEPARTMENT(deptid,deptname)
9/3/2012
ADBS
EMPLOYEE
address
manages
DEPARTMENT
deptname
bdate
EMPLOYEE(empid,name,address,bdate) DEPARTMENT(deptid,deptname,empid)
9/3/2012
ADBS
DEPARTMENT(deptid,deptname,empid)
WORKS(empid,projid,hours)
9/3/2012
ADBS
9/3/2012
ADBS
PROJECT
(projid,pname,startdate)
(assigndate)
9/3/2012
ADBS
Explanation
Due to the optionality of the relationship, the cascade rule is possible without any loss of important data. That is, whenever an employee is deleted from EMPLOYEE or a project is removed from PROJECT, the referencing tuples in WORKS can be deleted as well. NOTE: if the cascade rule is allowed, the restrict rule is also applicable.
9/3/2012 ADBS
PROJECT
(projid,pname,startdate)
(assigndate)
9/3/2012
ADBS
Explanation
Cascade* indicates that the cascade rule maybe used as long as the interface for removing an employee incorporates a checking mechanism for determining whether that employee is the only person working for a particular project. Due to the optional participation of EMPLOYEE in the relationship WORKS, the cascade rule is allowed. However, the mandatory participation of PROJECT in the relationship requires that at least one employee working for it.
9/3/2012 ADBS
PROJECT
(projid,pname,startdate)
(assigndate)
Due to mandatory participation of EMPLOYEE and the transformation rule, null values are absolutely not allowed in the foreign key
EMPLOYEE(empid,ename,projid,assignda te)
FK: projid references PROJECT DELETE restrict/cascade
PROJECT(projid,pname,startdate)
9/3/2012 ADBS
Explanation
Despite to the optional participation of PROJECT in relationship WORKS, the deletion of a project must not be cascaded in EMPLOYEE because deletion of any referencing tuples in EMPLOYEE result in loss of employee information. If however, the application really requires that employees are automatically removed when a project is shelved, the cascade rule must then be used.
9/3/2012 ADBS
PROJECT
(projid,pname,startdate)
(assigndate)
EMPLOYEE(empid,ename,projid,assigndate)
FK: projid references PROJECT DELETE restrict/cascade
PROJECT(projid,pname,startdate)
Due to the mandatory nature of the participation of PROJECT in the relationship WORKS, the deletion of a tuple in EMPLOYEE might lead to a project not having an employee working for it.
9/3/2012 ADBS
Database Normalization
ADVANCE Database System
Database Normalization
a technique for designing relational database tables to minimize duplication of information and, in so doing, to safeguard the database against certain types of logical or structural problems, namely data anomalies.
ADBS
78
Database Normalization
Example, when multiple instances of a given piece of information occur in a table, the possibility exists that these instances will not be kept consistent when the data within the table is updated, leading to a loss of data integrity.
ADBS
79
Database Normalization
A table that is sufficiently normalized is less vulnerable to problems of this kind, because its structure reflects the basic assumptions for when multiple instances of the same information should be represented by a single instance only.
ADBS
80
ADBS
81
ADBS
82
Normal Forms
1NF,2NF,3NF,BCNF,4NF,5NF Database theory describes a table's degree of normalization in terms of normal forms of successively higher degrees of strictness. A table in third normal form (3NF), for example, is consequently in second normal form (2NF) as well; but the reverse is not always the case.
Monday, September 03, 2012 ADBS 83
If the proper normal forms aren't followed, various undesirable side effects can occur in a database These side effects are commonly referred to as anomalies.
Insertion Anomalies Deletion Anomalies Update Anomalies
Monday, September 03, 2012 ADBS 84
Insertion Anomaly
This occurs when you cant add row into a table
Until the new faculty member is assigned to teach at least one course, his details cannot be recorded.
Monday, September 03, 2012 ADBS 85
Deletion Anomaly
This occurs when you cant delete row into a table, when the row you want to delete contains a important piece of information, or when the row you delete is the last one in the table that contains this piece of information.
ADBS
86
Deletion Anomaly
All information about Dr. Giddens is lost when he temporarily ceases to be assigned to any courses.
ADBS
87
Update Anomaly
These occur when there is unnecessary redundancy in the data.
ADBS
88
ADBS
89
Peter
Domingo
Kaye
Abad
ADBS
John
John John John
Dela Cruz
Dela Cruz Dela Cruz Dela Cruz
CS1
CS22 IS101 Math3a
Peter
Peter Peter Peter
Domingo
Domingo Domingo Domingo
CS2
CS3 Math3a Math6
Programming 2
Data Structures College Algebra Statistics
Peter
Kaye Kaye Kaye
Domingo
Abad Abad Abad
IS102
CS1 Math3a Engl2
ADBS
Quality Assurance
Intro to Computer Concepts College Algebra Comm Arts 2
91
ADBS
92
Functional Dependency
Attribute B is functionally dependent on attribute A if, for each value of attribute A, there is exactly one value of attribute B. Example, Employee Address is functionally dependent on Employee ID, because a particular Employee ID value corresponds to one and only one Employee Address value.
Employee Address Employee ID
ADBS Monday, September 03, 2012 93
ADBS
94
Patient_Telephone is not functionally dependent on the entire primay key (PatientID+RelativeID). The Patient_Telephone column is fully dependent on PatientID alone.
ADBS
95
Normalized 2NF
PatientID RelativeID Relationship 2490974 2490974 2490974 0803484 0803484 9857092 GGP001 GGP002 GGP003 PDE001 PDE002 AGE001 Father Guardian Mother Brother Uncle Sister PatientID Patient_Telephone 2490974 0803484 9857092 123-1342 789-3421 421-5986
ADBS
96
Transitive Dependency
A transitive dependency is an indirect functional dependency, one in which XZ only by virtue of XY and YZ. Example:
Column1 is directly dependent on the primary key column; another column, say Column2, is indirectly dependent on the primary key column because of its dependency on Column1. The dependency of Column2 to the primary key is by virtue of its dependency on Column1.
Monday, September 03, 2012 ADBS 98
Violation of 3NF
EmployeeID First_Name Last_Name Department Dept_Address
7623 Gail
6103 Keith 4503 Michael
Healy
Jordan Landon
MIS
MIS HR
3 Gauss Lane
3 Gauss Lane 6 Wiles Place
This table violates the 3NF because Dept_Address depends on Department, which is not part of the primary key.
ADBS
99
Normalized 3NF
EmployeeID First_Name Last_Name Department
8934 Anna
3049 Clarence 4589 Elliot 7623 Gail 6103 Keith 4503 Michael
Department
Burgin
Dillon Freeman Healy Jordan Landon
Research
Research Research MIS MIS HR
Dept_Address
Research
MIS HR
Monday, September 03, 2012
2 Ferman St.
3 Gauss Lane 6 Wiles Place
ADBS 100
ADBS
101
8934
8934 8934
9089 January
9089 February 9089 March
2
1.5 2
7623
7623 7623
8607 January
8607 February 8607 March
0
3 3
4503
4503 4503
Monday, September 03, 2012
3869 January
3869 February 3869 March
ADBS
2
8 0
102
Multi-valued dependency occurs when there is many-to-many relationship between two columns in a table.
Monday, September 03, 2012 ADBS 103
BookTitle
Monkeys are from Asteriod How to Exercise
Editor
Lisa Catherine
Smith023
Williams153 Williams153 Johnson823 Johnson823
How to Exercise
Monkeys are from Asteriod AP Programming Dogs are from Hale-Bopp Monkeys are from Asteriod
John
John Elaine Lisa Silvia