Good PPT for RDBMS starter
-
Upload
hcl-technologies -
Category
Education
-
view
133 -
download
1
description
Transcript of Good PPT for RDBMS starter
www.theoracletrainer.com
Introduction to
Database Management Systems
(DBMS)
www.theoracletrainer.com
Database Management Database Management System (DBMS)System (DBMS)
Definitions:Definitions:
Data: Data: Known facts that can be Known facts that can be recorded and that have implicit meaningrecorded and that have implicit meaning
Database:Database: Collection of related data Collection of related data Ex. the names, telephone numbers and Ex. the names, telephone numbers and
addresses of all the people you knowaddresses of all the people you know
Database Management System:Database Management System: A A computerized record-keeping systemcomputerized record-keeping system
www.theoracletrainer.com
DBMS (Contd.)DBMS (Contd.) Goals of a Database Management System:Goals of a Database Management System:
To provide an efficient as well as convenient To provide an efficient as well as convenient
environment for accessing data in a databaseenvironment for accessing data in a database Enforce information security: database Enforce information security: database
security, concurrence control, crash recoverysecurity, concurrence control, crash recovery
It is a general purpose facility for:It is a general purpose facility for: Defining Defining database database ConstructingConstructing database database Manipulating Manipulating databasedatabase
www.theoracletrainer.com
Benefits of database Benefits of database approach approach
Redundancy can be reducedRedundancy can be reduced Inconsistency can be avoided Inconsistency can be avoided Data can be sharedData can be shared Standards can be enforcedStandards can be enforced Security restrictions can be appliedSecurity restrictions can be applied Integrity can be maintainedIntegrity can be maintained Data independence can be providedData independence can be provided
www.theoracletrainer.com
DBMS FunctionsDBMS Functions
Data DefinitionData Definition Data ManipulationData Manipulation Data Security and IntegrityData Security and Integrity Data Recovery and ConcurrencyData Recovery and Concurrency Data DictionaryData Dictionary Performance Performance
www.theoracletrainer.com
Database SystemDatabase System
Stored Data Defn. Stored Database
Software to access stored data
Software to process queries/programs
DBMS
Software
Application Programs/Queries
Users
DATABASE
SYSTEM
(META-DATA).
www.theoracletrainer.com
Categories of Data Categories of Data ModelsModels
ConceptuaConceptuall
PhysicalPhysical RepresentationRepresentationalal
Data ModelData Model A set of concepts used to desscribe the A set of concepts used to desscribe the
structure of a databasestructure of a database By structure, we mean the data types, By structure, we mean the data types,
relationships, and constraints that relationships, and constraints that should holds for the datashould holds for the data
www.theoracletrainer.com
Database ArchitectureDatabase Architecture
Internal level(storage view)
Conceptual level(community user view)
External level(individual user views)
Database
www.theoracletrainer.com
An example of the three An example of the three levelslevels
SNo FName LName Age Salary
SNo FName LName Age Salary
SNo LName BranchNo
struct STAFF { int staffNo; int branchNo; char fName[15]; char lName[15]; struct date dateOfBirth; float salary; struct STAFF *next; /* pointer to next Staff record */};index staffNo; index branchNo; /* define indexes for staff */
BranchNo
Conceptual View
External View1
External View2
Internal View
www.theoracletrainer.com
SchemaSchema Schema: Description of data in terms of Schema: Description of data in terms of
a data modela data model Three-level DB Architecture defines Three-level DB Architecture defines
following schemas:following schemas: External Schema (or sub-schema)External Schema (or sub-schema)
Written using Written using external DDLexternal DDL Conceptual Schema (or schema)Conceptual Schema (or schema)
Written using Written using conceptual DDLconceptual DDL Internal SchemaInternal Schema
Written using Written using internal DDLinternal DDL or or storage structure storage structure definitiondefinition
www.theoracletrainer.com
Data IndependenceData Independence Change the schema at one level of a database Change the schema at one level of a database
system without a need to change the schema system without a need to change the schema at the next higher levelat the next higher level Logical data independence: Refers to the immunity Logical data independence: Refers to the immunity
of the external schemas to changes in the of the external schemas to changes in the conceptual schema e.g., add new record or fieldconceptual schema e.g., add new record or field
Physical data independence: Refers to the Physical data independence: Refers to the immunity of the conceptual schema to changes in immunity of the conceptual schema to changes in the internal schema e.g., adding new index should the internal schema e.g., adding new index should not void existing onesnot void existing ones
www.theoracletrainer.com
HIERARCHICAL
NETWORK
RELATIONAL
TABLEROW
COLUMN
VALUE
TYPES OF DATABASE TYPES OF DATABASE MODELSMODELS
www.theoracletrainer.com
DATA ANALYSIS
Entities - Attributes - Relationships - Integrity Rules
LOGICAL DESIGN
Tables - Columns - Primary Keys - Foreign Keys
PHYSICAL DESIGN
DDL for Tablespaces, Tables, Indexes
DATABASE DESIGN DATABASE DESIGN PHASESPHASES
Introduction to Introduction to Relational Relational Databases:Databases:
RDBMSRDBMS
www.theoracletrainer.com
Some Important TermsSome Important Terms Relation : Relation : a tablea table
Tuple : Tuple : a row in a tablea row in a table
Attribute : Attribute : a Column in a tablea Column in a table
Degree : Degree : number of attributesnumber of attributes
Cardinality : Cardinality : number of tuplesnumber of tuples
Primary Key : Primary Key : a unique identifier for the tablea unique identifier for the table
Domain :Domain : a pool of values from which specific a pool of values from which specific
attributes of specific relations draw their valuesattributes of specific relations draw their values
www.theoracletrainer.com
KeysKeys KeyKey
Super KeySuper Key
Candidate KeysCandidate Keys Primary KeyPrimary Key
Alternate KeyAlternate Key
Secondary KeysSecondary Keys
www.theoracletrainer.com
Keys and Referential Keys and Referential IntegrityIntegrity
sid cid grade
53666 carnatic101 C
53688 reggae203 B
53650 topology112 A
53666 history105 B
sid name age
53666 Jones 18
53688 Smith 18
53650 Smith 19
gpa
3.4
3.2
3.8
login
Jones@cs
Smith@eecs
Smith@math
Enrolled Student
Primary keyForeign key referring tosid of STUDENT relation
www.theoracletrainer.com
Conceptual Design Conceptual Design Using theUsing the
Entity- Entity- Relationship Relationship
ModelModel
www.theoracletrainer.com
Overview of Database Overview of Database DesignDesign
Conceptual design : (ER Model is Conceptual design : (ER Model is used at this stage.)used at this stage.)
Schema Refinement : Schema Refinement : (Normalization)(Normalization)
Physical Database Design and Physical Database Design and Tuning Tuning
www.theoracletrainer.com
Design Phases…Design Phases…Requirements Collection
& Analysis
Data Requirements
Functional Requirements Conceptual Design
Logical Design
Physical Design
User Defined Operations Data Flow DiagramsSequence Diagrams, Scenarios
Entity Types, Constraints , RelationshipsNo Implementation Details.
Ensures Requirements Meets the Design
Data Model Mapping – Type of Database is identified
Internal Storage Structures / Access Path / File Organizations
www.theoracletrainer.com
E-R ModelingE-R Modeling
EntityEntity is anything that exists and is is anything that exists and is
distinguishabledistinguishable Entity SetEntity Set
a group of similar entitiesa group of similar entities AttributeAttribute
properties that describe an entityproperties that describe an entity RelationshipRelationship
an association between entitiesan association between entities
www.theoracletrainer.com
NotationsNotations
ENTITY TYPE ( REGULAR )
WEAK ENTITY TYPE
RELATIONSHIP TYPE
WEAK RELATIONSHIP TYPE
www.theoracletrainer.com
CREATE TABLE Employees(ssn CHAR (11),name CHAR (20),lot INTEGER,PRIMARY KEY (ssn))
Employee
ssn name lotSSN NAME LOT
123- 22- 3666Attishoo 48
231- 31- 5368Smiley 22
131- 24- 3650Smethurst 35
Entity
Entity Set
Attributes
www.theoracletrainer.com
Types of Relationships
student ID cardIs issued
students courseenrols in
students teststake
1 1
1M
M M
1:1
1:M
M:M
www.theoracletrainer.com
ER Model
Department
did dname budgetsincesince
Works_inEmployee
ssn name lot
Reports_To
supervisor Sub-ordinate
www.theoracletrainer.com
CREATE TABLE Works_ In(ssn CHAR (11),did INTEGER,since DATE,PRIMARY KEY (ssn, did),FOREIGN KEY (ssn)REFERENCES Employees,FOREIGN KEY (did)REFERENCES Departments)
SSN DID SINCE
123-22-3666 51 1/1/91
123-22-3666 56 3/3/93
231-31-5368 51 2/2/92
ER Model (Contd.)
Works_ In
www.theoracletrainer.com
ManagesDepartment
did dname budgetsince
Employee
ssn name lot
Key Constraints
www.theoracletrainer.com
Key Constraints for Ternary Relationships
Department
did dnamesince
Works_inEmployee
ssn name lotbudget
Location
capacityaddress
www.theoracletrainer.com
Participation Constraints
Department
did dname budgetsince
ManagesEmployee
ssn name lot
Works_in
since
www.theoracletrainer.com
policyDependent
pnameagecost
Employee
ssn name lot
Weak Entities
www.theoracletrainer.com
ISA (‘is a’) Hierarchies
Employee
ssn name lot
Hourly_Emp
Hrs_worked
Hrly_wages
Contract_Emp
contractidIsA
www.theoracletrainer.com
Employee
ssn name lot
monitors
project
pid pbudget Started on
department
did dname budget
sponsors
until
Aggregation
www.theoracletrainer.com
Works_ In does not allow an employee to work in a department for two or more periods (why?)
Entity vs. Attribute
Works_inDepartment
did dname budgetfrom
Employee
ssn name lot to
www.theoracletrainer.com
Entity vs. Attribute (Contd.)
Works_inDepartment
did dname budget
from
Employee
ssn name lot
toDuration
www.theoracletrainer.com
managesDepartment
did dname budgetsince
Employee
ssn name lot DB
DB - Dbudget
Entity vs. Relationship
www.theoracletrainer.com
managesDepartment
did dname budget
since
Employee
ssn name lot
DBudgetMgr_apptAppt num
Entity vs. Relationship
www.theoracletrainer.com
Dependent
pname age
cost
Employee
ssn name lot
covers
Policy
policyid
Binary vs. Ternary Relationships
www.theoracletrainer.com
Dependent
pnameage
cost
Employee
ssn name lot
Beneficiary
Policypolicyid
Better Design
purchaser
Binary vs. Ternary Relationships
www.theoracletrainer.com
• Some constraints cannot be captured in ER diagrams:
• Functional dependencies
• Inclusion dependencies
• General constraints
Constraints Beyond the ER Model
www.theoracletrainer.com
E-R DiagramE-R Diagram
DEPARTMENT
DEPT_EMP
EMPLOYEE
EMP_DEP
DEPENDENT
PROJ_WORK
PROJ_MGR
PROJECT
SUPPLIER
SUPP_PART_PROJ
PART
PART_STRUCTURE
SUPP_PART
MM
M
M
M
M
M
M
M M
M
M
1
1 1
www.theoracletrainer.com
Example to Start with ….Example to Start with ….
An Example Database Application An Example Database Application called COMPANY which serves to called COMPANY which serves to illustrate the ER Model concepts and illustrate the ER Model concepts and their schema design.their schema design.
The following are collection from the The following are collection from the Client.Client.
www.theoracletrainer.com
Analysis…Analysis…
Company :Company :Organized into Departments, Each Organized into Departments, Each Department has a name, no and Department has a name, no and manager who manages the manager who manages the department. The Company keeps department. The Company keeps track of the date that employee track of the date that employee managing the department. A managing the department. A Department may have a Several Department may have a Several locations.locations.
www.theoracletrainer.com
Analysis…Analysis…
Department :Department :A Department controls a number of Projects A Department controls a number of Projects each of which has a unique name , no and a each of which has a unique name , no and a single Location.single Location.
Employee :Employee :Name, Age, Gender, BirthDate, SSN, Name, Age, Gender, BirthDate, SSN, Address, Salary. An Employee is assigned to Address, Salary. An Employee is assigned to one department, may work on several one department, may work on several projects which are not controlled by the projects which are not controlled by the department. Track of the number of hours department. Track of the number of hours per week is also controlled.per week is also controlled.
www.theoracletrainer.com
Analysis….Analysis….
Keep track of the dependents of Keep track of the dependents of each employee for insurance policies each employee for insurance policies : We keep each dependant first : We keep each dependant first name, gender, Date of birth and name, gender, Date of birth and relationship to the employee.relationship to the employee.
www.theoracletrainer.com
DEPARTMENT ( Name , Number , { Locations } , Manager, Start Date )
PROJECT( Name, Number, Location , Controlling Department )
EMPLOYEE(Name (Fname, Lname) , SSN , Gender, Address, Salary
Birthdate, Department , Supervisor , (Workson ( Project , Hrs))
DEPENDENT ( Employee, Name, Gender, Birthdate , Relationship )
www.theoracletrainer.com
Example …Example …
Manage:Manage: Department and Employee Department and Employee Partial Partial ParticipationParticipation
Relation Attribute : StartDate.Relation Attribute : StartDate. Works For:Works For:
Department and EmployeeDepartment and Employee Total ParticipationTotal Participation
www.theoracletrainer.com
Example…Example…
Control :Control : Department , ProjectDepartment , Project Partial Participation from Department Partial Participation from Department Total Participation from ProjectTotal Participation from Project Control Department is a RKA.Control Department is a RKA.
Supervisor :Supervisor : Employee, EmployeeEmployee, Employee Partial and RecursivePartial and Recursive
www.theoracletrainer.com
Example …Example …
Works – On :Works – On : Project , EmployeeProject , Employee Total ParticipationTotal Participation Hours Worked is a RKA.Hours Worked is a RKA.
Dependants of:Dependants of: Employee , DependantEmployee , Dependant Dependant is a WeakerDependant is a Weaker Dependant is Total , Employee is Dependant is Total , Employee is
Partial.Partial.
www.theoracletrainer.com
One Possible mapping of the One Possible mapping of the Problem Statement Problem Statement
Works For Department
Name No Loc
Controls
Project
Name No Loc
WorksOn
manages
Sdate
Hours
Depend On
Name Sex Bdate
Relationship
Supervise
s
Employee Address
Fname
SexSSN
Name
Bdate
Sal
Lname
Dependent
www.theoracletrainer.com
www.theoracletrainer.com
www.theoracletrainer.com
www.theoracletrainer.com
Schema Schema Refinement andRefinement andNormalizationNormalization
www.theoracletrainer.com
Normalization and Normalization and Normal FormsNormal Forms
Normalization:Normalization: DecomposingDecomposing a larger, complex table into several a larger, complex table into several
smaller, simpler ones.smaller, simpler ones. Move from a lower Move from a lower normal formnormal form to a higher to a higher
Normal form.Normal form. Normal Forms:Normal Forms:
First Normal Form (1NF)First Normal Form (1NF) Second Normal Form (2NF)Second Normal Form (2NF) Third Normal Form (3NF)Third Normal Form (3NF) *Higher Normal Forms (BCNF, 4NF, 5NF ....)*Higher Normal Forms (BCNF, 4NF, 5NF ....)
In practice, 3NF is often good enough.In practice, 3NF is often good enough.
www.theoracletrainer.com
Why Normal FormsWhy Normal Forms
The first question to ask is whether The first question to ask is whether
any refinement is needed!any refinement is needed!
If a relation is in a certain normal If a relation is in a certain normal
form (BCNF, 3NF etc.), it is known form (BCNF, 3NF etc.), it is known
that certain kinds of problems are that certain kinds of problems are
avoided/ minimized. This can be used avoided/ minimized. This can be used
to help us decide whether to help us decide whether
decomposing the relation will help.decomposing the relation will help.
www.theoracletrainer.com
The Evils of RedundancyThe Evils of Redundancy
Redundancy is at the root of several Redundancy is at the root of several problems associated with relational problems associated with relational schemasschemas
More seriously, data redundancy causes More seriously, data redundancy causes several anomalies: insert, update, deleteseveral anomalies: insert, update, delete
Wastage of storage.Wastage of storage. Main refinement technique: Main refinement technique:
decomposition (replacing ABCD with, decomposition (replacing ABCD with, say, AB and BCD, or ACD and ABD).say, AB and BCD, or ACD and ABD).
www.theoracletrainer.com
Refining an ER Diagram - Refining an ER Diagram - BeforeBefore
Department
did dname budgetsince
Works_inEmployee
ssn name lot
www.theoracletrainer.com
Refining an ER Diagram - Refining an ER Diagram - AfterAfter
Works_in
since
Employee
ssn name
lot
Department
did dname budget
www.theoracletrainer.com
First Normal FormFirst Normal Form A table is in 1NF, if every row contains exactly one A table is in 1NF, if every row contains exactly one
value for each attribute.value for each attribute. Disallow multivalued attributes, composite attributes Disallow multivalued attributes, composite attributes
and their combinations.and their combinations. 1NF states that :1NF states that :
domains of attributes must include only atomic (simple, domains of attributes must include only atomic (simple, indivisible) values and that value of any attribute in a tuple indivisible) values and that value of any attribute in a tuple must be a single value from the domain of that attribute.must be a single value from the domain of that attribute.
By definition, any relational table must be in 1NF.By definition, any relational table must be in 1NF.
www.theoracletrainer.com
Functional Dependencies Functional Dependencies (FDs)(FDs)
Provide a formal mechanism to Provide a formal mechanism to
express constraints between express constraints between
attributes attributes
Given a relation R, attribute Y of R is Given a relation R, attribute Y of R is
functionally dependent on the functionally dependent on the
attribute X of R if & only if each X-attribute X of R if & only if each X-
value in R has associated with it value in R has associated with it
precisely one Y-value in R.precisely one Y-value in R.
www.theoracletrainer.com
Full DependencyFull Dependency
Concept of full functional Concept of full functional
dependencydependency A FD x A FD x y y is a full functional is a full functional
dependency if removal of any attribute dependency if removal of any attribute
A from X means that the dependency A from X means that the dependency
does not hold any more.does not hold any more.
www.theoracletrainer.com
Partial DependencyPartial Dependency
An F.D. x An F.D. x y is a partial dependency y is a partial dependency
if there is some attribute A if there is some attribute A X that X that can be removed from X and the can be removed from X and the dependency will still hold.dependency will still hold.
www.theoracletrainer.com
Example: Constraints on Example: Constraints on Entity SetEntity Set
123- 22- 3666 Attishoo231- 31- 5368131- 24- 3650434- 26- 3751612- 67- 4134
SmileySmethurstGulduMadayan
4822353535
88558
1010
77
10
4030303240
S N L R W H
58
710
R W123- 22- 3666 Attishoo231- 31- 5368131- 24- 3650434- 26- 3751612- 67- 4134
SmileySmethurstGulduMadayan
4822353535
S N L4030303240
H8R
85
58
www.theoracletrainer.com
Second Normal Form Second Normal Form (2NF)(2NF)
A relation schema R is in 2NF if:A relation schema R is in 2NF if: it is in 1NF andit is in 1NF and
every non-prime attribute A in R is fully every non-prime attribute A in R is fully
functionally dependent on the primary functionally dependent on the primary
key of R.key of R.
2NF prohibits 2NF prohibits partial dependenciespartial dependencies..
www.theoracletrainer.com
2NF: An Example2NF: An Example Emp{Eno, Dept, ProjCode, Hours}Emp{Eno, Dept, ProjCode, Hours}
Primary key: {Eno, ProjCode}Primary key: {Eno, ProjCode} {Eno} -> {Dept}, {Eno, ProjCode} -> {Hours}{Eno} -> {Dept}, {Eno, ProjCode} -> {Hours}
Test of 2NFTest of 2NF {Eno} -> {Dept}: {Eno} -> {Dept}: partial dependency.partial dependency. Emp is in 1NF, but not in 2NF.Emp is in 1NF, but not in 2NF.
Decomposition:Decomposition: Emp {Emp {EnoEno, Dept}, Dept} Proj {Proj {Eno, ProjCodeEno, ProjCode, Hours}, Hours}
www.theoracletrainer.com
Transitive DependencyTransitive Dependency
An FD X An FD X Y in a relation schema R Y in a relation schema R
is a transitive dependency if is a transitive dependency if there is a set of attributes Z that is not there is a set of attributes Z that is not
a subset of any key of R, and a subset of any key of R, and both X both X Z and Z Z and Z Y hold. Y hold.
www.theoracletrainer.com
Third Normal FormThird Normal Form A relation schema R is in 3NF if A relation schema R is in 3NF if
It is in 2NF and It is in 2NF and
No nonprime attribute of R is transitively No nonprime attribute of R is transitively
dependent on the primary key.dependent on the primary key.
3NF means that each non-key attribute value in any tuple 3NF means that each non-key attribute value in any tuple is truly dependent on the Primary Key and not even is truly dependent on the Primary Key and not even partially on other attributes.partially on other attributes.
3NF prohibits 3NF prohibits transitive dependenciestransitive dependencies..
www.theoracletrainer.com
3NF: An Example3NF: An Example Emp{Eno, Dept, Dept_Head}Emp{Eno, Dept, Dept_Head}
Primary key: {Eno}Primary key: {Eno} {Eno} -> {Dept}, {Dept} -> {Dept_Head}{Eno} -> {Dept}, {Dept} -> {Dept_Head}
Test of 3NFTest of 3NF {Eno} -> {Dept} -> {Dept_Head}: Transitive {Eno} -> {Dept} -> {Dept_Head}: Transitive
dependency.dependency. Emp is in 2NF, but not in 3NF.Emp is in 2NF, but not in 3NF.
Decomposition:Decomposition: Emp {Emp {Eno, DeptEno, Dept}} Dept {Dept, Dept_Head}Dept {Dept, Dept_Head}
www.theoracletrainer.com
Boyce –Codd Normal Boyce –Codd Normal FormForm
The intention of BCNF is that- 3NF The intention of BCNF is that- 3NF does not satisfactorily handle the does not satisfactorily handle the case of a relation processing two or case of a relation processing two or more composite or overlapping more composite or overlapping candidate keys candidate keys
www.theoracletrainer.com
BCNF ( Boyce Codd BCNF ( Boyce Codd Normal Form)Normal Form)
A Relation is said to be in Boyce A Relation is said to be in Boyce Codd Normal Form (BCNF) if and Codd Normal Form (BCNF) if and only if every determinant is a only if every determinant is a candidate key.candidate key.