Database Management 2. course. Reminder Concept of DBMSs: – Gathering all the data and...
-
Upload
molly-tyler -
Category
Documents
-
view
213 -
download
0
Transcript of Database Management 2. course. Reminder Concept of DBMSs: – Gathering all the data and...
Database Management
2. course
Reminder
• Concept of DBMSs:– Gathering all the data and correspondence into one DB– Answer the question with the help of this DB
• 3 levels of a DB– Conceptual model: A world described by the DB– Implementation/representation model: a model
understandable for the DBMS (structured records, tables, fields, etc.)
– Physical model: DBMS implemented on the computer (files, programs)
Structure of the DBMS
• The user has permission for the smaller part of the DB: View
Conceptual model
Implementation model
Physical model
View1 View2 View3
Relational data model
• Relation:table+constraints
• Column headers:attribute/domain
• Rows:data records/tuples
• Database:Set of tables
Relationships
• 1:1
• 1:N
• N:M
Person Owns Car
Actor Acts Play
• Superkey/Key/Foreign key• Anomalies
– Insertion: superkey needs too much data– Update: Redundancy– Deletion: Different objects stored together
Normalization
• If a relation is in 0 NF (can be put in tables) and does not contain multiple field then it is in at least 1 NF
• If a relation is in 1 NF and does not contain partial functional dependency then it is in at least 2 NF
• If a relation is in 2 NF and does not contain transitive functional dependency then it is in at least 3 NF
3 NF vs. BCNF
• A 3 NF is not in BCNF if– There are several possible keys,– these keys are composite, and– there is a common attribute in the keys
Decomposition has to be…???
Decomposition
• Has to be– Lossless: By uniting/jointing the decomposed tables,
the original tables before normalization can be created
– Preserve dependencies: After decomposition, the originial dependencies can be infered from the new relation’s dependencies.
• Closure of an attribute set• Armstrong axioms• How to check?
Today
• Administration• Concurrent processing• Entity-relationship diagrams
Tasks of the database supervisor
• Administration• Protect the systems• Protect the users• Design• Keep in touch with the users• Maintain, save, backup
Logical independence
Conceptual model
Implementation model
Physical model
View1 View2 View3
Physical independence
Conceptual model
Implementation model
Physical model
View1 View2 View3
Transaction
• Unit• Basic operation in the DB• Has to preserve the consistency of the DB
Concurrent processing
• Basic requirement for fast execution• Inconsistency• User is independent
Steps of record processing
1. Search2. Import to the workspace of the user3. Process, update4. Write back to database
Wait-for graph
• Ek(Ti, Tj): Ti gets mean k before Tj
• Ti: ith transaction
Rollback
• Rollback journal• Difference table
Log
• Atomicy• WAL protocol• Crash?
Logfile
• Content• Concatenated or rolled back• Archived• Invisible
Tasks of the DB administrator
• Data independence• Comfort• Security, secrecy, accuracy• Concurrent processes• Reduce response time• Develop• Expenses
Structure of the DBMS
• LayersQuery optimization and
-execution
Relational operators
Files and permissions
Buffering
Handling storage
DB
Handling concurrency andrecovery control is takeninto consideration
Entity relationship (ER) diagrams
Steps of designing a database
• Survey the needs• Design the conceptual model• Create the implementation model• Design the physical model
Steps of the conceptual designing
1. Define the entities and relationships2. Define the info about the entites3. Define the constraints
Elements of the ER model
• Entities– Properties– Key
• Relationships– 1:1– 1:N– N:M
Entity set
• Set of similar entities• Key• Codomain
Notation
• Entity set:
• Attribute:
• Key attribute:
Student
sidname
avg
Relationships and relationship sets
• Relationship:– David works in the purchasing department
• Relationship set:– n-ary relation:, elements of the relation: ,
Notation
• Relationship set:
• M:N relationship:
• N:1 relationship:
lot
dname
budgetdid
sincename
Works_In DepartmentsEmployees
ssn
Reports_To
lot
name
Employees
super-visor
ssn
Types of relationships
lot
dname
budgetdid
since
name
Works_In DepartmentsEmployees
ssn
dname
budgetdid
since
lot
name
ssn
Employees DepartmentsManages
ER model of a university
• What assumptions are there?
• How to check correctness? (Ask questions!)
Students
Professor teaches
Department
faculty
major offers
Courses
enrollmentadvisor
Practice
• Can a student have more than one major?
• Can a student have more than one advisor?
• Can a professor work in more than one department?
• Can a course have more than one teacher?
• Can a department be without teacher?
Students
Professor teaches
Department
faculty
major offers
Courses
enrollmentadvisor
Constraints
• Does all the departments have a manager?– Participation constraint– Bold or double line
lot
name dnamebudgetdid
sincename dname
budgetdid
since
Manages
since
DepartmentsEmployees
ssn
Works_In
Weak entity set
• Attributes of the entity set are not enough– Notation: double or bold line for the entity set
Studios(name, addr)Crews (number, studioName)Unit-of (number, studioName, name)name=studioName!!!
Example
• Disney crew #3 is one of the crews of the Disney studio
• Crews: (Disney-crew-#3, Disney)• Unit-of: (3, Disney, Disney)
• Solution:• Merge to: (3, Disney)• Same as Crews leave it for good
Subclass, inheritance (ISA)
Length Title Year
WeaponMovies
CriminalCartoon
isa isa
isa isa
Criminal cartoon
Voice
Actor
• Special properties can be given• Different relationships with other entities• Inheritance• Overlap constraint• Covering constraint
Decisions in design
• Entity or property?• Entity or relationship?• Relationship: binary or ternary?• Constraints
Entity or attribute?
• Should the address of an employee be an entity or an attribute of the worker table?
• Attribute:– Simple– Atomic
Example
name
Employees
ssn lot
Works_In
from to
dname
budgetdid
Departments
dname
budgetdidname
Departments
ssn lot
Employees Works_In
Durationfrom to
Entity or relationship
Manages2
name dnamebudgetdid
Employees Departments
ssn lot
dbudgetsince
dname
budgetdid
DepartmentsManages2
Employees
name
ssn lot
since
Managers dbudget
ISA
Binary or ternary relationship?
• Every policy belongs to an employee• Every dependent is connected to a policy• Not appropriate modeling:
agepname
DependentsCovers
name
Employees
ssn lot
Policies
policyid cost
Rather binary
• Every policy belongs to an employee• Every dependent is connected to a policy• Appropriate modeling:
Beneficiary
agepname
policyid cost
Policies
Purchaser
name
Employees
ssn lot
Dependents
Rather ternary
• Order contracts connecting Procurers (P), Suppliers (S), and Products (Pr)
• With binary relations: – P orders Pr– Supplier supplies for P– S delivers Pr
pricename
productwriter
name
Procurer
pid addr
supplier
name addr
count
Conclusions
• First step: gathering the needs• ER-model: similar to human thinking• Basic terms: entity, relationship, attribute• Other terms: weak entity, ISA relationship,
constraints
• Constraints are important• ER-model is subjective• Good ER-model gives good DB schema
• Literature:• Jeffrey D. Ullman, Jennifer Widom: A first
course in database systems• www.uni-obuda.hu/users/varkonyi.teri
Thank you for your attention!