Relational Database Management Systems

Welcome to this course on Relational Database Management Systems!

1

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.

Copyright © 2004, Infosys Technologies Ltd

2

ER/CORP/CRS/DB07/003 Version No: 2.0

2

Session Plan (1of 3)
Day1
–Data Processing –Basic DBMS concepts –ER modeling

Day2
–ER modeling continued –Extended ER features –Logical database design –Functional dependencies –Normalization –Denormalization

Day3
–DDL –DML –Aggregate functions

Copyright © 2004, Infosys Technologies Ltd

3

ER/CORP/CRS/DB07/003 Version No: 2.0

3

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

Copyright © 2004, Infosys Technologies Ltd

4

ER/CORP/CRS/DB07/003 Version No: 2.0

4

Session Plan (3 of 3)
Day 7 – – – – – Concurrency continued Database Recovery Log file Deferred Database update Immediate Database update

Copyright © 2004, Infosys Technologies Ltd

5

ER/CORP/CRS/DB07/003 Version No: 2.0

5

Third ed. Elmasri. Second ed. C. Sixth ed. Navathe. Infosys Technologies Ltd 6 ER/CORP/CRS/DB07/003 Version No: 2. McGraw-Hill International editions.J.0 6 .. Addison Wesley "An introduction to Database Systems"..References “Database system concepts”. Computer Science series(1991) "Fundamentals of Database Systems".Date. Henry F Korth. Abraham Silberschatz. Narosa Publications Copyright © 2004.

RDBMS-Day1 Data Processing Basic DBMS concepts Basic RDBMS concepts Conceptual Database Design ER Modeling Notations 7 .

Data Processing Data collection Recording Sorting Classifying Calculating Storing & retrieving Summarizing Communicating Copyright © 2004. Infosys Technologies Ltd 8 ER/CORP/CRS/DB07/003 Version No: 2.0 8 .

On-line (interactive) processing: Transactions are processed as & when they appear.0 9 . Infosys Technologies Ltd 9 ER/CORP/CRS/DB07/003 Version No: 2. Real-time processing: It is a parallel time relationship with on-going activity & the information produced is useful in controlling the current/dynamic activity.Data Processing modes Batch processing: Transactions are collected in a group & processed together. Copyright © 2004.

10 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2.0 •In the traditional approach. •Application programs go through the file system to access these flat files 10 . we used to store information in flat files which are maintained by the file system under the operating system’s control.Traditional Method of Storage Application Programs File System Files A B C D Copyright © 2004.

S. 11 .Ways of storing data in files 4176 4181 4183 4203 4204 4176 4181 4183 4203 4204 Aniruddha Sarkar Manoj Saha Moushumi Dharchoudhury Suryanarayana D. tab etc. •Records consist of various fields which are delimited by a space . SBU1 Vivek Rai SBU1 SBU1 SBU1 SBU1 SBU1 SBU1 Predefined length Copyright © 2004.0 •Data used to be stored in the form of records in the files.V. 11 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2.S.V.S. Vivek Rai AniruddhaSarkar SBU1 ManojSaha SBU1 MoushumiDharchoudhury SBU1 SuryanarayanaD. •There used to be special characters to mark end of records and end of files. comma .

If the deletion is missed out on even one of the files. it has to be done in all the files where the employee data occurs. the same information was repeated in multiple files. an employee’s information to be deleted. it would leave the data inconsistent. •When a particular data had to be updated . say for example. Since data was spread across multiple files and there was no formal way of maintaining relationships between these files.Problems:Traditional approach DATA DEPENDENCY MULTIPLE FILES UPDATE PROBLEM LOSS OF FLEXIBILITY REDUNDANCY INCONSISTENCY Copyright © 2004. 12 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2. This led to redundancy. 12 . This led to loss of flexibility.0 •Data spread across multiple files where dependent on each other .

The Database Technology Database Computer based record-keeping system Collection of interrelated (persistent) data Records & maintains data Database Management System Collection of files that contain related data Managed by a specialized piece of software known as a database management system (DBMS) Layer of abstraction between the application programs and the file system Copyright © 2004. 13 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2. modify.0 •Application programs request the DBMS to retrieve. insert or delete data for them 13 .

for interacting with the file system. the ‘c’ file handling functions. For interacting with the DBMS we would be using a Query language called SQL 14 . the DBMS acts as a layer of abstraction on top of the File system. 14 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2. You might have observed that.0 • • Now. we were using high level language functions for example.Where does the RDBMS fit in? File System interface Position of DBMS DBMS interface Copyright © 2004.

user management. physical storage control 15 . performance analysis.0 Services provided by a DBMS •Data management •Data definition •Transaction support •Concurrency control •Recovery •Security & integrity •Utilities. backup.facilities like data import & export. 15 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2. logging & audit.Three-layer Architecture External View External View External View DBMS interface Conceptual layer DBMS interface Internal layer Copyright © 2004.

Advantages of a DBMS Data independence Reduction in data redundancy Better security Better flexibility Effective data sharing Copyright © 2004. Users and application programs need not know exactly where or how the data is stored in order to access it 2.Support for unforeseen (ad hoc) information requests are better supported .better flexibility 4.0 1. Data can be more effectively shared between users and/or application programs Data can be stored for long term analysis (data warehousing) 16 . 16 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2. Proper database design can reduce or eliminate data redundancy and confusion 3.

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 . 17 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2.0 •DBA is a key person and takes care of most administrative tasks as mentioned in the slide •Database designers.Users of a DBMS Database Administrator (DBA) – – – – – Managing information contents Liaison with users Enforcing security and integrity rules Strategizing backup & recovery Monitoring performance Database designers Application Programmers End users Copyright © 2004.

Oracle.IDMS •Relational Model . DB2 18 . 18 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2.0 Commercial Packages •Hierarchical Model .IMS •Network Model .Database Technologies Hierarchical Model Network Model Relational Model Object-Oriented Copyright © 2004.

19 . 19 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2. actually. RDBMS: A DBMS that manages the relational database.Relational Model Basics Data is viewed as existing in two dimensional tables known as relations A relation (table) consists of unique attributes (columns) and tuples (rows) Tuples are unique Sometimes the value to be inserted into a particular cell may be unknown. the data is stored under the file system only. blank or an empty string Relational Database: Any database whose logical organization is based on relational data model. or it may have no value. Copyright © 2004.0 •Though logically data is viewed as existing in the form of two dimensional tables. •The RDBMS provides an abstraction on top of the file system and gives an illusion that data resides in the form of tables. This is represented by a null Null is not the same as zero.

0 20 .000 t u p l e s 1049 Shyam 25 19.000 1067 Raj 22 14.400 Copyright © 2004. 20 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2.A sample relation Attributes Emp table E# 1023 EmpName Ram Age 23 Salary 25.000 1098 Hari 23 18.

However. a unique value for its primary key.e if the primary key is composite. For e.Keys Super key Candidate key Primary key Foreign key Copyright © 2004. by definition. S# alone or P# alone would not uniquely identify a row of the shipment table. 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.Ename and Emailid. in an Employee table. 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. any subset of these set of attributes would not identify a row uniquely For example. A foreign key is a copy of the whole of its parent primary key i. Ename are two overlapping candidate keys. E#. that is sufficient to distinguish every tuple in the relation from every other one. 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. “S# . 21 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2.g. Each super key is called a candidate key A candidate key is all those set of attributes which can uniquely identify a row. in a shipment table. But.0 Superkey An attribute. or group of attributes. P# ” is a candidate key. (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 Copyright © 2004. 23 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2.0 23 .

24 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2. the database schema and the physical design 24 .0 The outcome of each stage is correspondingly called the conceptual schema.Design levels of a database Conceptual design Logical design Physical database design Copyright © 2004.

Also known as Entity type. a particular student Attributes: Properties/characteristics that describe entities Relationships: Associations between entities Copyright © 2004. Entity instance: a particular member of the entity type e. 25 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2.g.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.0 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. 26 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2. divorced. If the key consists of two or more attributes in combination.0 26 . married. the employee id of an employee etc. 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. it is called a composite key Copyright © 2004.

27 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2. » Can be split into day.g Date of joining of the employee.Simple Vs composite attribute Simple attribute: cannot be divided into simpler components E.g age of an employee Composite attribute: can be split into components E. month and year Copyright © 2004.0 27 .

Single Vs Multi-valued Attributes Single valued : can take on only a single value for each entity instance E.g. age of employee. skill set of employee Copyright © 2004. There can be only one value for this Multi-valued: can take many values E. 28 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2.0 28 .g.

• E.g.Stored Vs Derived attribute Stored Attribute: Attribute that need to be stored permanently. name of an employee Derived Attribute: Attribute that can be calculated based on other attributes . • E. 29 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2.0 29 . : years of service of employee can be calculated from date of joining and current date Copyright © 2004.g.

Regular Vs.g. Weak entity type Regular Entity: Entity that has its own key attribute.g. Weak entity: Entity that depends on other entity for its existence and doesn’t have key attribute of its own E. policy holder etc. E.0 The spouse data is identified with the help of the employee id to which it is related 30 . : spouse of employee Copyright © 2004. 30 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2.customer. student .: Employee.

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 Copyright © 2004.. 31 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2. shyam works –for electrical department .etc are relationship instances of the relationship.0 E.g if Works-for is the relationship between the Employee entity and the department entity.sc department. then Ram works for Comp. works-for 31 .

0 32 .g employee manager-of employee is unary employee works-for department is binary customer purchase item. 32 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2.Degree of a Relationship Degree: the number of entity types involved • One Unary • Two Binary • Three Ternary E. shop keeper is a ternary relationship Copyright © 2004.

Cardinality Relationships can have different connectivity – – – one-to-one one-to-many many-to-many (1:1) (1:N) (M:N) E. 33 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2.0 The minimum and maximum values of this connectivity is called the cardinality of the relationship 33 .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 Copyright © 2004.

g Employee Head-of Department Employee: partial Department: total Copyright © 2004. 34 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2. So only few instances of employee entity participate in the above relationship.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. So department entity’s participation is total and employee entity’s participation is partial in the above relationship 34 .0 All employees will not be head-of some department. But each department will be headed by some employee.

ER modeling -Notations 35 .

Entity Usually a noun in singular Represented by a rectangle with a label First letter in capitals Employee Copyright © 2004. 36 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2.0 36 .

37 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2.0 Represented by ellipses connected to the entity type by straight lines 37 .Attributes DOB Name Address E# Employee Designation Copyright © 2004.

Key attribute DOB Name Address E# Employee Designation The key attribute is underlined Copyright © 2004. 38 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2.0 38 .

39 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2.0 Indicated by a double lined ellipse as shown in the figure 39 .Multivalued Attribute DOB Name Designation E# Employee skill set Address Copyright © 2004.

Composite attribute floor building DOB Name Address E# Employee Designation Copyright © 2004.0 Represented by an ellipse from which other ellipses emanate and represent the component attributes. 40 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2.g Address 40 . E.

Usually the convention is to read the ER diagram from top to bottom and from left to right.0 •A relationship is represented as a diamond between two entity types. •The relationship above is read as student enrolls-in course 41 . •It has a label that explains the relationship. 41 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2.Relationship student enrols in course Copyright © 2004. •So. the relationship name is so chosen as to make sense when read from left to right.

Unary Relationship Employee Manages Copyright © 2004.0 •A unary relationship is represented as a diamond which connects one entity to itself as a loop. 42 . some instances of employee manage other instances of Employee. 42 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2. •The relationship above means.

0 43 . 43 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2.Role names Role names may be added to make the meaning more explicit subordinate Employee Manager Manages Copyright © 2004.

Binary Relationship Employee Works for Department Copyright © 2004.0 A relationship between two entity types 44 . 44 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2.

45 .Ternary Relationship Medicine Doctor Prescription Patient Copyright © 2004. 45 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2.0 A relationship connecting three entity types.

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:1 relationship 1:1 PERSONS Sits_on CHAIR • P1 • P2 • P3 • P4 Copyright © 2004.

47 Infosys Technologies Ltd 47 .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 Copyright © 2004.

M:1 relationship • L1 •L3 • L2 •L8 • L4 •L5 Street Name • C1 • C2 • C3 City Number Amount Borrowed_by Customer Loan Copyright © 2004.0 48 . 48 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2.

49 Infosys Technologies Ltd 49 .M:N relationship M:N STUDENTS M N 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 Copyright © 2004.

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. 1:M. inconsistency etc The Database model consists of three layers RDBMS handles data in the form of relations.Summary The file based approach has problems of redundancy.0 50 . N:M Copyright © 2004. Attributes can be simple/composite. stored/derived Relationship types represent collaboration between entity types. 50 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2. Cardinality of relationships could be 1:1. single valued/multivalued. Relationships could be unary/binary/ternary.

Thank You! Copyright © 2004.0 51 . 51 Infosys Technologies Ltd ER/CORP/CRS/DB07/003 Version No: 2.

Sign up to vote on this title
UsefulNot useful