RDBMS
RDBMS
RDBMS
Course Objectives
To introduce basic RDBMS concepts To create familiarity with SQL To create familiarity with Embedded-SQL To introduce the concept of transaction processing and discuss certain issues in the same.
Day2
ER modeling continued Extended ER features Logical database design Functional dependencies Normalization Denormalization
Day3
DDL DML Aggregate functions
Session Plan (2 of 3)
Day 4
Grouped results Sub queries Relational algebra Use of EXISTS and NOT EXISTS
Day 5
Views Concept of an index Embedded SQL
Day 6
Transaction processing concepts OLTP Database integrity Security Concurrency
Session Plan (3 of 3)
Day 7 Concurrency continued Database Recovery Log file Deferred Database update Immediate Database update
References
Database system concepts, Henry F Korth, Abraham Silberschatz, Second ed., McGraw-Hill International editions, Computer Science series(1991) "Fundamentals of Database Systems", Elmasri, Navathe, Third ed, Addison Wesley
RDBMS-Day1
Data Processing Basic DBMS concepts Basic RDBMS concepts Conceptual Database Design ER Modeling Notations
Data Processing
Data collection Recording Sorting Classifying Calculating Storing & retrieving Summarizing Communicating
File System
Files A B C D
In the traditional approach, we used to store information in flat files which are maintained by the file system under the operating systems control. Application programs go through the file system to access these flat files
10
4176 4181 4183 4203 4204 4176 4181 4183 4203 4204
Aniruddha Sarkar Manoj Saha Moushumi Dharchoudhury Suryanarayana D.V.S.S. Vivek Rai AniruddhaSarkar SBU1 ManojSaha SBU1 MoushumiDharchoudhury SBU1 SuryanarayanaD.V.S. SBU1 Vivek Rai SBU1
Predefined length
Data used to be stored in the form of records in the files. Records consist of various fields which are delimited by a space , comma , tab etc. There used to be special characters to mark end of records and end of files.
11
Problems:Traditional approach
DATA DEPENDENCY MULTIPLE FILES UPDATE PROBLEM
LOSS OF FLEXIBILITY
REDUNDANCY
INCONSISTENCY
Data spread across multiple files where dependent on each other . This led to loss of flexibility. Since data was spread across multiple files and there was no formal way of maintaining relationships between these files, the same information was repeated in multiple files. This led to redundancy. When a particular data had to be updated , say for example, an employees information to be deleted, it has to be done in all the files where the employee data occurs. If the deletion is missed out on even one of the files, it would leave the data inconsistent.
12
Application programs request the DBMS to retrieve, modify, insert or delete data for them
13
Now, the DBMS acts as a layer of abstraction on top of the File system. You might have observed that, for interacting with the file system, we were using high level language functions for example, the c file handling functions. For interacting with the DBMS we would be using a Query language called SQL
14
Three-layer Architecture
External View External View External View
DBMS interface
Conceptual layer
DBMS interface
Internal layer
Copyright 2004, 15 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2.0
Services provided by a DBMS Data management Data definition Transaction support Concurrency control Recovery Security & integrity Utilities- facilities like data import & export, user management, backup, performance analysis, logging & audit, physical storage control
15
Advantages of a DBMS
Data independence Reduction in data redundancy Better security Better flexibility Effective data sharing
1. Users and application programs need not know exactly where or how the data is stored in order to access it 2. Proper database design can reduce or eliminate data redundancy and confusion 3.Support for unforeseen (ad hoc) information requests are better supported - better flexibility 4. Data can be more effectively shared between users and/or application programs Data can be stored for long term analysis (data warehousing)
16
Users of a DBMS
Database Administrator (DBA)
Managing information contents Liaison with users Enforcing security and integrity rules Strategizing backup & recovery Monitoring performance
DBA is a key person and takes care of most administrative tasks as mentioned in the slide Database designers, design the database elements Application programmers, make use of the various database elements and write programs to retrieve data from them End users use the DBMS
17
Database Technologies
Hierarchical Model Network Model Relational Model Object-Oriented
Commercial Packages Hierarchical Model - IMS Network Model - IDMS Relational Model - Oracle, DB2
18
Though logically data is viewed as existing in the form of two dimensional tables, actually, the data is stored under the file system only. The RDBMS provides an abstraction on top of the file system and gives an illusion that data resides in the form of tables.
19
A sample relation
Attributes Emp table
E# 1023 EmpName Ram Age 23 Salary 25,000
t u p l e s
1049
Shyam
25
19,000
1067
Raj
22
14,000
1098
Hari
23
18,400
20
Keys
Super key Candidate key Primary key Foreign key
Superkey An attribute, or group of attributes, that is sufficient to distinguish every tuple in the relation from every other one. Each super key is called a candidate key
A candidate key is all those set of attributes which can uniquely identify a row. However, any subset of these set of attributes would not identify a row uniquely For example, in a shipment table, S# , P# is a candidate key. But, S# alone or P# alone would not uniquely identify a row of the shipment table.
Primary key The candidate key that is chosen to perform the identification task is called the primary key and any others are alternate keys Every tuple must have, by definition, a unique value for its primary key. A primary key which is a combination of more than one attribute is called a composite primary key Foreign key A foreign key is a copy of a primary key that has been exported from one relation into another to represent the existence of a relationship between them. A foreign key is a copy of the whole of its parent primary key i.e if the primary key is composite, then so is the foreign key Foreign key values do not (usually) have to be unique Foreign keys can also be null A composite foreign key cannot have some attribute(s) null and others non-null Overlapping candidate keys: Two candidate keys overlap if they involve any attribute in common. For e.g, in an Employee table, E#,Ename and Emailid, Ename are two overlapping candidate keys. (they have Ename in common) Attribute that does not participate in any candidate key is called a Non-key attribute
21
Conceptual design
Entity Relationship modeling
22
Data modeling
Study of basic properties and inter-relationships among data items to properly represent them in the basic data structures of a database Two popular techniques: ER modeling and Normalization
23
Conceptual design
Logical design
The outcome of each stage is correspondingly called the conceptual schema, the database schema and the physical design
24
ER modeling
ER modeling : A graphical technique for understanding and organizing the data independent of the actual database implementation Entity: Any thing that may have an independent existence and about which
we intend to collect data. Also known as Entity type.
25
Attributes
The set of possible values for an attribute is called the domain of the attribute Example:
The domain of attribute marital status is just the four values: single, married, divorced, widowed The domain of the attribute month is the twelve values ranging from January to December
Key attribute: The attribute (or combination of attributes) that is unique for every entity instance
E.g the account number of an account, the employee id of an employee etc.
If the key consists of two or more attributes in combination, it is called a composite key
26
27
28
29
Weak entity: Entity that depends on other entity for its existence and doesnt
have key attribute of its own E.g. : spouse of employee
The spouse data is identified with the help of the employee id to which it is related
30
Relationships
A relationship type between two entity types defines the set of all associations between these entity types Each instance of the relationship between members of these entity types is called a relationship instance
E.g if Works-for is the relationship between the Employee entity and the department entity, then Ram works for Comp.sc department, shyam works for electrical department ..etc are relationship instances of the relationship, works-for
31
Degree of a Relationship
Degree: the number of entity types involved One Unary Two Binary Three Ternary E.g employee manager-of employee is unary employee works-for department is binary customer purchase item, shop keeper is a ternary relationship
32
Cardinality
Relationships can have different connectivity
one-to-one one-to-many many-to-many (1:1) (1:N) (M:N)
E.g employee head-of department (1:1) student enrolls course (m:n) lecturer offers course (1:n) assuming a course is taught by a single lecturer
The minimum and maximum values of this connectivity is called the cardinality of the
relationship
33
Relationship Participation
Total : Every entity instance must be connected through the relationship to another instance of the other participating entity types Partial: All instances need not participate
E.g Employee Head-of Department Employee: partial Department: total
All employees will not be head-of some department. So only few instances of employee entity participate in the above relationship. But each department will be headed by some employee. So department entitys participation is total and employee entitys participation is partial in the above relationship
34
ER modeling -Notations
35
Entity
Usually a noun in singular Represented by a rectangle with a label First letter in capitals
Employee
36
Attributes
DOB Name Address
E#
Employee
Designation
37
Key attribute
DOB Name Address
E#
Employee
Designation
38
Multivalued Attribute
DOB Name Designation E# Employee skill set Address
39
Composite attribute
floor building
E#
Employee
Designation
Represented by an ellipse from which other ellipses emanate and represent the component attributes. E.g Address
40
Relationship
student
enrols in
course
A relationship is represented as a diamond between two entity types. It has a label that explains the relationship. Usually the convention is to read the ER diagram from top to bottom and from left to right. So, the relationship name is so chosen as to make sense when read from left to right. The relationship above is read as student enrolls-in course
41
Unary Relationship
Employee
Manages
A unary relationship is represented as a diamond which connects one entity to itself as a loop. The relationship above means, some instances of employee manage other instances of Employee.
42
Role names
Role names may be added to make the meaning more explicit
subordinate
Employee
Manager
Manages
43
Binary Relationship
Employee
Works for
Department
44
Ternary Relationship
Medicine
Doctor
Prescription
Patient
45
1:1 relationship
1:1
PERSONS Sits_on CHAIR
P1 P2 P3 P4
Copyright 2004, 46 Infosys Technologies Ltd
C1 C2 C3 C4
ER/CORP/CRS/DB07/003 Version No: 2.0
One instance of entity type 1 is connected to exactly one other entity instance of entity type 2
46
1:m relationship
1:M
DEPT
1 EMPLOYS m
EMPLOYEE
D1 D2 D3 D4
E1 E3 E2 E8 E7 E4 E5 E6
ER/CORP/CRS/DB07/003 Version No: 2.0
47
M:1 relationship
L1 L3 L2 L8 L4 L5
Street Name
C1 C2 C3
City
Number
Amount
Borrowed_by
Customer
Loan
48
M:N relationship
M:N
STUDENTS
Taught_by S1 T1
TEACHERS
S3 S2 S8 S7 S4
S5 S6
T3 T2 T8 T7 T4 T5 T6
ER/CORP/CRS/DB07/003 Version No: 2.0
49
Summary
The file based approach has problems of redundancy, inconsistency etc The Database model consists of three layers RDBMS handles data in the form of relations, tuples and fields Keys identify tuples uniquely ER modeling is a diagrammatic representation of the conceptual design of a database Entity types represent things Entity type could be strong or weak Attributes represent characteristics. Attributes can be simple/composite, single valued/multivalued, stored/derived Relationship types represent collaboration between entity types. Relationships could be unary/binary/ternary. Cardinality of relationships could be 1:1, 1:M, N:M
50
Thank You!
Copyright 2004, 51 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2.0
51