0% found this document useful (0 votes)
272 views

Unit-I: Database Concepts: A Relational Approach: Database - Relationships - DBMS

RDBMS-Class Notes

Uploaded by

ajita
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
272 views

Unit-I: Database Concepts: A Relational Approach: Database - Relationships - DBMS

RDBMS-Class Notes

Uploaded by

ajita
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 15

UNIT-I

Database Concepts: A Relational approach: Database – Relationships – DBMS –


Relational Data Model – Integrity Rules – Theoretical Relational Languages. Database
Design: Data Modeling and Normalization: Data Modeling – Dependency – Database Design
– Normal forms – Dependency Diagrams – De -normalization – Another Example of
Normalization.

INTRODUCTION
A database is an electronic store of data. It is a repository that stores information
about different “things” and also contains entities, entity sets and relationships among entity
sets.

The following are the basic terms to describe the structure of a database.

 Entity
 Data
 Attributes
 Entity set
 Database
 Relationships

Entity
An entity is a thing or object of importance about which data must be captured. They
may be a person, place, event or item.

Data
The fact describing an entity is known as data. For example: if you were a mentor in
a department of a college, you would like to have all the information of the students such as
student name, addresses etc., these individual facts are known as data.

Attributes
The characteristics of each entity are described by attributes.
For example: The student entity may have the following attributes: 1. Name,
2.Rollno or Regno, 3.Fathers Name, 4. Phone No, 5. Address etc..,

Entity set
All the related entities are collected together to form an entity set. For example:
Assume employee_det is an entity set, it contains the details of each employee, where each
employee is a single entity.ie, a collection of related entities (employee) forms an entity set
(employee_det).

Database
All the entity set forms a database.
For example: A college database may have the following entity sets.
1. Course_det, 2.student_det, 3.books_det etc.

Relationships
The interactions between the entity sets are known as Relationships. The interactions
are described using active verbs. For example: each student (entity) in a student_det (entity
set) takes a course (entity) in Course_det. Therefore a relationship must exists between the
two entity sets( Course_det and Student_det).
Here, takes is an active verb.

College Database
Entity set 1 Entity set 2
↓ ↓

Student_det Course_det

Name Rollno Course Section Attributes

Anand 101 BCA A entity

Arun 102 BCOM B entity


(Fig 1) Entity, Entity set, Attributes, Database.

The above figure illustrates that each student (entity) takes (relationship) a course
(entity).

RELATIONSHIPS IN DATABASE

The relationships in database are as follows:


1. One-to-One relationship
2. One-to-Many relationship
3. Many-to-Many relationship

1. One-to-one relationship(1:1)
A one-to-one relationship is written as 1:1 in short form.
It exists between two entity sets where each entity has only one matching entity in
another entity set and vice versa.
For example 1:Each college has one principal and a principal has no other college to
manage. This indicates 1:1 relationship
College_det Principal_det
Name_of_col Address Name_of_principal Address
Kg AAAAA….. X AAAAA…..
Psg BBBBB…… Y BBBBB……
(Fig 2.1) 1:1 Relationship
The above table illustrates each principal has a single college to work and each
college contains a single principal.
For example 2:
Employee Manager

1:1
E1 M1
E2 M2
E3 M3
E4 M4
(Fig 2.2) 1:1 Relationship
One-to-One relationship exists between two entity sets. If x and y are two entity sets, if
an entity in entity set x has only one relationship with an entity in entity set y and vice versa.
Consider that employee manages one department and the department contains only one
as a manager.

2. One-to-Many relationship(1:M)

A one-to-many relationship is written as 1: M in short forms. It exists between two entity


sets X and Y where each entity in X has many matching entities in another entity set Y, but
not vice versa.ie. Y has only one matching entity in entity set X.
For example 1:
The following fig(1.c) illustrates 1:M relationship, here a Tutor(Ram) of a class has
number of student to guide. But each student has a single Tutor to interact.

Student_det(Y)
Faculty_tab(X)
Name_of_Tutor Name_of_student Class

X BCA
1.Ram Y BCA
Z BCA
2.Ragu A BCOM
B BCOM
C BCOM
(Fig 3.1) 1: M Relationship

For example 2:
Department Faculty

1:M
D1 F1
D2 F2
D3 F3
D4 F4

(Fig 3.2) 1: M Relationship

3. Many-to-Many-relationship
A many-to-many relationship is written as M: M or M:N in short form. It exists
between two entity sets where each entity has many matching entities in another entity set
and vice versa.
Employee (X) Project(Y)
Name_of_employee Name_of_project
Anu P1
Ambika P2
Anu P2
(Fig 4) M: N or M : M Relationship

DATABASE MANAGEMENT SYSTEM (DBMS)


What is a DBMS?
 A database management system (or DBMS) is essentially nothing more than a
computerized data-keeping system.
 Users of the system are given facilities to perform several kinds of operations on such
a system for either manipulation of the data in the database or the management of the
database structure itself.
 Database Management Systems (DBMSs) are categorized according to their data
structures or types.
 There are several types of databases that can be used on a mainframe to exploit
z/OS®: inverted list, hierarchic, network, or relational.
 Mainframe sites tend to use a hierarchical model when the data structure (not data
values) of the data needed for an application is relatively static.
 For example, a Bill of Material (BOM) database structure always has a high level
assembly part number, and several levels of components with subcomponents.
 The structure usually has a component forecast, cost, and pricing data, and so on.
 The structure of the data for a BOM application rarely changes, and new data
elements (not values) are rarely identified.
 An application normally starts at the top with the assembly part number, and goes
down to the detail components.
 Hierarchical and relational database systems have common benefits. RDBMS has the
additional, significant advantage over the hierarchical DB of being non-navigational.
By navigational, we mean that in a hierarchical database, the application programmer
must know the structure of the database.
 The program must contain specific logic to navigate from the root segment to the
desired child segments containing the desired attributes or elements.
 The program must still access the intervening segments, even though they are not
needed.
 The remainder of this section discusses the relational database structure.

USER

APPLICATIONS DBMS DB

OPERATING SYSTEM SOFTWARE

HARDWARE
(Fig 5) Database System
DBMS (Database Management System)
Database Management System (DBMS) includes software packages such as
ORACLE, Microsoft Access, Visual Fox Pro, etc..,

Database (DB)
Database includes tables and other database object which are used for the storing of
data.

Operating System Software


Operating system software is software installed in a system.
Hardware
Hardware is nothing but personal computers, mini computers and mainframes in a
network environment.

Applications
Applications are nothing but user creates a data entry form, reports, etc..,

User
A person who uses the database management system such as system administrator,
programmer, user, etc..,
Data are the raw material .Information is processed, manipulated, collected or
organized data (i.e., information is a collection of data).The information is produced when an
application transforms data managed by DBMS. The database system is also called as
decision making system, information system (IS).

RELATIONAL DATABASE MANAGEMENT SYSTEM (RDBMS)

A DBMS based on relational model is known as Relational database management system


(RDBMS).An RDBMS not only manages data but it is also responsible for following
functions:

 DATA DICTIONARY: An RDBMS creates data dictionary like a user creates a


database. The data dictionary is a system structure that stores metadata. The metadata
include table names, attributes names, data types, physical space, and relationships
and so on.
 It manages all day to day transactions.
 It performs book keeping duties.
 DATA SEARCH: When a user requests data, the RDBMS searches through the
DATA DICTIONARY, filters the data and displays the result in a readable and
understandable form.
 USER VALIDATION: It allows user to specify validation rules. i.e., it sets
validation rules for example, M and F entry for the attribute gender to avoid incorrect
values.
 SECURITY ACCESS: It secures access through password, encryption and restricted
user rights.
 BACKUP AND RECOVERY: It provides backup and recovery procedures for
physical security of data.
 DATA SHARING: It allows user to share data with data locking capabilities.
 IMPORT AND EXPORT UTILITIES: It provides import and export utilities to use
data created in other database, spreadsheet etc.,
 NORMALIZATION: The user is able to design a database with less redundancy.

THE RELATIONAL DATABASE MODEL


E. F. Codd developed the relational database model in 1970.The model is based on
mathematical set theory, and it uses a relation as the building block of the database.

Relation
The relation is represented by a two dimensional, flat structure known as a table. The
user views the data in a logical, two dimensional structure without knowing the mathematical
details or the physical aspects of the data.

Table
A table is a matrix of rows and columns in which each row represents an entity and
each column represents an attribute. As per database theory, a table is described as entity set
(ref: fig 1.a).In daily practice, the term table, relation, and entity set are used interchangeably.

Tuple
In relational terminology, a row is referred to as a tuple(ref :fig 1.a). In a relational
database it is easy to establish relationship between tables. i.e., entity corresponds to tuple.

Degree of the relation


The number of columns in a table is called the degree of the relation or table.
For example: If a table has four columns then the table is of degree 4.The order of
columns is immaterial and there is no predefined order to rows of a table.

Domain
The set of all possible values that a column may have is called the domain of the
column. Two domains are the same only if they have same meaning and use.
For example: Consider train_ticketno, Bus_ ticketno represents the ticket number and
uses the numeric values but their domain is different.

Train Bus
train_ticketno Bus_ticketno
1 1
2 2
3 3
4 4
(Fig 6) Domain

Where Train and Bus are the two different domains.


Terminology comparison
Relational terminology File system terminology
Entity set or table or relation File or table
Entity or row or tuple Record
Attribute or column Field
(Fig 7) Terminology Comparison
Key
A key is a minimal set of columns used to uniquely define any row in a table.

Primary key
When a single column used as a unique identifier it is known as primary key. A single
column key is used to describe each row if it is uniquely defines each row.
Roll no Student_nm
1 Kumar
2 anand
3 vimal
(Fig 8) Primary Key
Here the column Roll_no uniquely identifies each row. Therefore the Roll_no acts as a
primary key.

Composite primary key or Composite key


When a combination of columns is used as a unique identifier it is known as
Composite primary key or Composite key.
A combination of column is used to describe each row if a single column is not
uniquely defines each row.
Date_of_exam Subject
1/9/2013 Software Engineering
2/9/2013 C++
3/9/2013 Software Engineering
1/9/2013 Management theory
2/9/2013 Management information system
3/9/2013 Business accounting
(Fig 9) Composite Key
Here the columns Date_of_exam, Subject, Department do not uniquely identify each
row. Therefore the combination of Date_of_exam and Subject can be used as a composite
primary key.

Secondary key
Sometimes, it is not possible to identify or retrieve a row from a table using the
primary key, if the primary key may be an employee_number or an register_number or an
department_number etc., In such cases data is retrieved by using the employee_name or
student_name or department_name and these are known as Secondary Key.

Surrogate Key
If none of the columns is a candidate for the primary key in a table. In such a case
database designers using extra column as a primary key instead of using composite key, such
a key is known as surrogate key.
ID Customer_number Vendor_number Term _number
1 1 101 1
2 2 102 2
3 3 103 3
4 1 104 2
5 2 102 3
6 6 103 1
(Fig 10) Surrogate Key
Here the customer_number, vendor_number, term_number are not a candidate key for
if any one of the above is a primary key. Therefore an extra column ID is known as the
surrogate key.
Foreign key
In a relational database, tables are related to each other through a common column. A
key in a table which is used to refer a column in another table is known as a foreign key.

Product table:

Product
Product_id (acts as a primary key ) Name
P1 Bread
P2 biscuit
P3 chocolate

Sales table:
Sales
Sales_no Product_id (acts as a quantity
foreign key)
S1 P1 3
S2 P2 4
S3 P1 6
(Fig 11) Foreign Key and Primary Key

INTEGRITY RULES

Main purpose is to maintain consistency of the data in a table. If consistency is


compromised the data are not useable. There are two types of integrity rules. They are as
follows:
 Entity Integrity
 Referential Integrity

1. Entity integrity (a feature of Primary key)


In entity integrity no column in a primary key is null.
A zero or a space is not considered to be a null value.
RDBMS software strictly does not allow the user to enter a row without a unique value
in the primary key column.
2. Referential integrity (a feature of foreign key)
A foreign key value may be a null value or it must exist as a value of primary key in
the reference table.
Referential integrity is not fully supported by all available RDBMS system but
ORACLE supports it.
ORACLE does not allow user to declare a foreign key if it is does not exists as a
primary key in another table. If a user enters a value in the foreign key column it cross
references the reference primary key in the other table to confirm the existence of such a
value.

THEORETICAL RELATIONAL LANGUAGES


There are two theoretical relational languages by E. F. Codd to use with the relational
model:
 Relational Algebra / Procedural Language
 Relational Calculus / Non – Procedural Language

In third generation high level compilers languages can be used to manipulate data but
they work with only one row at a time.
But relational languages can work on the entire table or on a group of rows. The
multiple tow manipulation does not even need the looping structure.
1. RELATIONAL ALGEBRA
It is a procedural language the user accomplishes desired results by using a set of
operations in a sequence.
It uses set operations on table to profuse new resulting table.
In oracle all operations names are not actually used as programming terms.
Union Compatible:
Two tables are said to be union compatible if both tables have the same degree.
Domains of the corresponding columns in the two tables are the same.

OPERATIONS USED BY RELATIONAL ALGEBRA

 Union
 Intersection
 Difference
 Projection
 Selection
 Product
 Assignment
 Join
 Division

Union
The union of tow tables results in retrieval of all rows that are in one or both the tables.
Duplicate rows are eliminated from the resulting table.
To perform union operation both tables should be union compatible.
Example:
Project 1
No. Location Customer
1 Coimbatore Nibu
2 Ooty Nishanth
3 Bangalore Nirishma

Project 2
No. Location Customer
1 Coimbatore Nibu
4 Chennai Nippin
5 Kerala Nisha

Table C = Project 1 U Project 2

Table C
No. Location Customer
1 Coimbatore Nibu
2 Ooty Nippin
3 Bangalore Nisha
4 Chennai Nippin
5 Kerala Nisha

Intersection
Intersection of two tables produces a time with rows that are common in both the
tables.
Intersection of two tables produces a time with rows that are common in both the
tables.
Example:
Project 1
No. Location Customer
1 Coimbatore CCC
2 Chennai AAA
3 Bangalore BBB

Project 2
No. Location Customer
1 Coimbatore CCC
4 Hyderabad DDD
5 Pune EEE

Project 3 = Project 1 Ω Project 2

Table C
No. Location Customer
1 Coimbatore CCC
In this example only one row from Project 1 and Project 2 has same domain values.
Therefore, the resulting table Project 3 has only one row.

Difference
Difference of two tables produces a table with rows that are present in the first table but not
in the second table.
Difference operation can be performed on union compatible tables.
Example:
Project 1
No. Location Customer
1 Coimbatore CCC
2 Chennai AAA
3 Bangalore BBB

Project 2
No. Location Customer
1 Coimbatore CCC
4 Hyderabad DDD
5 Pune EEE

Project 3 = Project 1 - Project 2


Project 3
No. Location Customer
2 Coimbatore AAA
3 Bangalore BBB
In this example the resulting table Project 3 contains rows which are only in the table
Project 1. As mathematics set theory A-B≠B-A.
Projection
Difference of two tables produces a table with rows that are present in the first table
but not in the second table.
Difference operation can be performed on union compatible tables.
Example:

Parts
No. Part Description Vendor
11 Nut AA
22 Bolt BB
33 Washer CC

Table E =Parts (Part Description, Vendor)


Table E
Part Description Vendor
Nut AA
Bolt BB
Washer CC

In this example, the projection operator retrieves the columns part describe, vendor
from the table parts and creates a new table, Table E.

Projection
Selection operator selects the rows form ta table based on conditions. Conditional
operators (=,<>,<,>,<=,>=) and the logical operators (AND, OR, NOT) are used along with
the columns and values to create conditions. It returns the horizontal slices of a table.
Example:

Parts
P No. Part Description Vendor Cost
11 Nut AA 20
22 Bolt BB 5
33 Washer CC 40

Table F =Sel(Parts: Cost >10.00)

Table F
P No. Part Description Vendor Cost
11 Nut AA 20
33 Washer CC 40

In this example the selection operator retrieves only the rows which satisfy the
condition given inside the query. In the parts table the first and the last rows retrieved to
form the resulting Table F.

Product
A product of two tables is the combination of everything in both tables.
It is known Cartesian Product.
In the product operation, if the first table has x rows and second table has y rows the
resulting table will have x * y rows.
If the first table has m columns and the second table has n columns then the
resulting table will have m + n columns.

Example:

Department Student
CS S1
CA S2
CT
IT

Table G = Department * Student

Table G
Department Student
CS S1
CS S2
CA S1
CA S2
CT S1
CT S2
IT S1
IT S2
In this example, the first table department has one column and second table student also
has one column and the second table student also has one column and the resulting table,
Table G has two columns.
The first table department has three rows and the second table student has two rows
so that the resulting table, Table G has six rows.

Assignment
The assignment operation creates a new table from the existing table.
Assignment gives us as ability to name new tables that are based on other tables. Assignment
is note an ORACLE term.
Example:

Department Student
CS S1
CA S2
Table G = Department * Student
CT
IT

Table G
Department Student
CS S1
CS S2
CA S1
CA S2
CT S1
CT S2
IT S1
IT S2
viii. Join
Join is a most important operation because of its ability to get related data from a
number of tables.
Join is based on common set of values which does not have the same name in both
tables but must have same domain in both tables.
When a join is based on equality of value it is known as equijoin or natural join.
Other types of joins are outer join, non-equijoin and self –join that are based on
operators other than equal operator.
Example:
Employee
ENo Ename Dept no Pjt No
101 E1 10 1
102 E2 20 3
103 E3 30 6
104 E4 20 5
105 E5 10 7
Department

Dept no Dept Name


10 Production
20 Supply
30 Marketing
Table H = Join(Employee, Department :Dept No= Dept No)

Table H
ENo Ename Dept no Pjt No Dept Name
101 E1 10 1 Production
102 E2 20 3 Supply
103 E3 30 6 Marketing
104 E4 20 5 Supply
105 E5 10 7 Production

The expression is read as


“join a row in employee table with a row in department table where the
department number value in the employee table is equal to the department number
value in the department table.”
Join operation involves a series of operation. They are as listed below:
 Product operation is performed first which results in 15 rows and 6 columns.
 Selection operation is performed next to select rows where department number values are
equal.
 Finally projection is performed to eliminate duplicated attribute.

Division
The division operation is the most different operation in a relational algebra.
It is nor same as mathematical division.
In relational algebra it identifies rows in one table that have a certain relationship to
all rows in another table.
Example:

Proj ProjParts

ENo
1
2
3

P No. Part No.


1 11
2 33
3 11
1 22
2 11
Table I = ProjParts / Proj

Table I
ENo
11
The columns of Table I are those form dividend table ProjParts that are not in the
divisor table Proj.
The rows of Table I are the subset of the projection ProjParts(PartNo).
The row PartNo will be in Table I if and only if (P No, PartNo) is in the dividend
Project Parts.
For every value of PartNo in the divisor project.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy