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

Bilal Dbms Unit-1

This document provides an introduction to database management systems. It discusses key concepts such as data, information, databases, and DBMS. It describes the functions of a DBMS including concurrency, security, backup/recovery, and integrity. Advantages of DBMS are reduced errors, improved security and data access. DBMS were needed due to drawbacks of file systems like data redundancy, difficult access, and integrity and concurrency issues. DBMS applications include banking, airlines, universities, and more. The document contrasts file systems with DBMS and describes the view of data in DBMS architecture.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Bilal Dbms Unit-1

This document provides an introduction to database management systems. It discusses key concepts such as data, information, databases, and DBMS. It describes the functions of a DBMS including concurrency, security, backup/recovery, and integrity. Advantages of DBMS are reduced errors, improved security and data access. DBMS were needed due to drawbacks of file systems like data redundancy, difficult access, and integrity and concurrency issues. DBMS applications include banking, airlines, universities, and more. The document contrasts file systems with DBMS and describes the view of data in DBMS architecture.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 101

DATABASE

DB

MANAGEMENT
UNIT-I M

Presented By
S Mohammad Bilal J
SYSTEM Assistant professor
Department I.T
VCE
Course Outcomes
✓ C01- Demonstrate design and implementation of a database for a given problem domain.

✓ C02- Construct Queries in Relational algebra, relational calculus and SQL.

✓ C03- Apply Normalization techniques to reduce data redundancy in data base.

✓ CO4- Analyze various transaction control and recovery methods to keep data base consistent.

✓ C05- Construct the file of data records by using appropriate storage and access structure.
Text Books
1. Raghurama Krishnan, Johannes Gehrke., Database Management Systems, 3rd Edition,Tata McGraw-
Hill, New Delhi, India, 2014.

2. Abraham Silberschatz, Henry F. Korth, S. Sudarshan., Database System Concepts,7th Edition, McGraw-
Hill, New Delhi, India, 2019.
UNIT-1

✓Introduction to DBMS, ✓Database systems versus file systems,


01 02
✓Applications of DBMS ✓View of data

✓Database users and administrators, ✓Database Design- E-R diagrams,


03 04
✓Database system structure. ✓Entities and Entity sets, Attributes

✓Relationships and relationship sets ✓Introduction to the relational model


05 06
✓Additional features of the E-R model ✓logical database design

✓ Relational algebra operations ✓Relational calculus operators


07 08
✓Basic queries and basic queries
Introduction to Database Management System
i. Data:
✓ It is defined as raw facts or observations.

✓ It is the raw material from which useful information is derived.

✓ It takes variety of forms, including numeric data, text and voice and images.

✓ It is collection of facts and figures which can be processed to produce information.


Example: Weights, prices, costs, number of items sold etc.

ii. Information:
✓ Data that have been processed in such a way as to increase the knowledge of the person who uses
the data.

✓ The database today may contain either data or information.


iii. Database:
✓ The Organized Collection of Data, which contains related information.

✓ It is also used to organize the data in the form of a table, schema, views, and reports, etc.

✓ Example: The college Database organizes the data about the admin, staff, students and faculty etc.

✓ By using the database, the information can be easily retrieved, inserted, and deleted.

iv. Database Management System:


✓ DBMS provides an interface to perform various operations like database creation, storing data in it,
updating data and a lot more.

✓ It provides protection and security to the database.

✓ In the case of multiple users, it also maintains data consistency.

✓ The goal of DBMS is to provide a way to store and retrieve information in a convenient and efficient
manner.
Introduction to Database Management System

Functions of a DBMS:

i. Concurrency : concurrent access (meaning 'at the same time') to the same database by
multiple users.

ii. Security : security rules to determine access rights of users.

iii. Backup and recovery : processes to back-up the data regularly and recover data if a problem
occurs.

iv. Integrity : database structure and rules improve the integrity of the data.
Advantages of DBMS
✓ Reduced updating errors.

✓ Improved data security.

✓ Reduced data redundancy.

✓ Greater data integrity and independence from applications programs.

✓ Improved data access to users through use of query languages.

✓ Reduced data entry, storage, and retrieval costs.


Need of DBMS
✓ Before the DBMS, organizations typically stored information using a “File Processing Systems”.

✓ Example of such systems are File Handling in High Level Languages like C, Basic and COBOL etc.,

✓ These systems have Major disadvantages to perform the Data Manipulation.

✓ So to overcome those drawbacks now we are using the DBMS.

✓ Database systems are designed to manage large amount of information.

✓ Management of data involves both defining structures for storage of information and providing
mechanisms for the manipulation of information.

✓ Database system must ensure the safety of the information stored, when the system crashes or
attempts at unauthorized access.
Database System Applications
✓ The Databases are used in many areas and many applications. Some of the Database Applications.

1. Banking :For customer information, accounts, and loans, and banking transactions.

2. Airlines :For reservations and schedule information. Airlines were among the first to use

databases in a geographically distributed manner.

3. Universities :For student information, course registrations, and grades.

4. Credit card transactions :For purchases on credit cards and generation of monthly statements.

5. Telecommunication :For keeping records of calls made, generating monthly bills, maintaining balances on

prepaid calling cards, and storing information about the communication networks.
Database System Applications

6. Finance :For storing information about holdings, sales, and purchases of financial

instruments such as stocks and bonds.

7. Sales :For customer, product, and purchase information.

8. Manufacturing :For tracking production of items in factories, inventories of items in warehouses

and orders for items.

9. Human resources :For information about employees, salaries, payroll taxes and benefits.

10. Railway Reservation Systems :For reservations and schedule information.


Drawbacks of File System
Before the Database Management System come into existence organizations used to store the data in Files.

1. Data redundancy and inconsistency:


✓ Multiple file formats, duplication of information in different files.

2. Difficulty in Accessing Data:


✓ Need to write a new program to carry out each new task and the data retrieval is not convenient and efficient.

3. Integrity Problems:
✓ Hard to add new constraints or change existing ones
Drawbacks of File System
4. Atomicity Problems:
✓ Failures may leave database in an inconsistent state with partial updates carried out.

Example:

Transfer of funds from one account to another should either complete or not happen at all.

5. Concurrent access Anomalies:


✓ Data accessed by multiple users.

✓ Uncontrolled concurrent accesses can lead to inconsistencies.

6. Security Problems:
✓ Not every user of the database system should be able to access all the data.
Database System Vs File System
File Management System Database Management System
✓It is easy-to-use system to store general files which ✓It is used when security constraints are high.
require less security and constraints.

✓Complex to maintain non-redundant data. ✓Due to normalization easy to maintain non-redundant data.

✓Less degree of concurrency. ✓More degree of concurrency.

✓Data Inconsistency is more. ✓Data Inconsistency is less.

✓Centralization is hard. ✓Centralization is achieved.

✓User locates the physical address of the files to ✓User is unaware of physical address where data is stored.
access data .

✓Security is low. ✓Security is high.

✓It stores unstructured data ✓It stores structured data


view of data
✓ The three level of DBMS architecture is:

✓ The top level of that architecture is “view level”.


View Level
✓ The view level provides the “view of data” to the users and hides the irrelevant
details such as data relationship, database schema, constraints, security etc from
Logical Level
the user.

✓ To fully understand the view of data, you must have a basic knowledge of 2
components
Physical Level

i. Data Abstraction

ii. Instance and Schema.


view of data
i. Data Abstraction:
✓ Database systems are made-up of complex data structures.

✓ To ease the user interaction with database, the developers hide internal irrelevant details from users.

✓ This process of hiding irrelevant details from user is called data abstraction.

✓ The term “irrelevant” used here with respect to the user, it doesn’t mean that the hidden data is not relevant with
regard to the whole database.

✓ It just means that the user is not concerned about that data.
view of data
✓ There are three levels of abstractions

i. Physical level abstraction:


✓ This is the lowest level of data abstraction.

✓ It describes how data is actually stored in database.

✓ You can get the complete data structure details at this level.

ii. Logical level abstraction:


✓ It describes what data is stored in database.

iii. View level abstraction:


✓ This level describes the user interaction with database system.
view of data
Example -1:
✓ When you are booking a train ticket, you are not concerned how data is processing at the back end when you
click “book ticket”.

✓ You are just concerned about the message that pops up when your ticket is successfully booked.

✓ This doesn’t mean that the process happening at the back end is not relevant, it just means that you as a user
are not concerned what is happening in the database.
view of data
Example-2:
✓Let’s say we are storing customer information in a customer table:

✓At physical level these records can be described as blocks of storage (bytes, gigabytes, terabytes etc.) in memory.
These details are often hidden from the programmers.

✓At the logical level these records can be described as fields and attributes along with their data types, their
relationship among each other can be logically implemented. The programmers generally work at this level because
they are aware of such things about database systems.

✓At view level, user just interact with system with the help of GUI and enter the details at the screen, they are not
aware of how the data is stored and what data is stored; such details are hidden from them.
view of data
ii. Instance and schema:
✓ Design of a database is called the schema.

Example:

✓ An employee table in database exists with the following attributes:

EMP_NAME , EMP_ID, EMP_ADDRESS, EMP_CONTACT

✓ Schema defines the attributes of tables in the database.

✓ Schema helps the database users to understand the relationship between data.

✓ Schema is of three types:

a) Physical schema

b) logical schema

c) view schema
view of data
view of data
i. Physical Schema :
✓The design of a database at physical level is called physical schema.
✓ It describes the physical storage structure of the database.
✓How the data stored in blocks of storage is described at this level.
ii. Logical schema :
✓Design of database at logical level is called logical schema
✓Programmers and database administrators work at this level
✓ what type of data records gets stored in data structures.
iii. View schema :
✓Design of database at view level is called view schema.
✓This generally describes end user interaction with database systems.
✓This schema allows data access to be customized at the level of individual users or groups of users.
view of data
Definition of instance:
✓The data stored in database at a particular moment of time is called instance of database.

Example:
✓ we have seen the schema of table “employee”.
✓ Let’s see the table with the data now.

✓At this moment the table contains two rows (records). This is the current instance of the table “employee”
because this is the data that is stored in this table at this particular moment of time.
Database Users and Administrators
DATABASE USERS:
✓Database users are the persons who interact with the database and take the benefits of database.
✓Different types of users are:
i. Naive users
ii. Application programmers
iii. Stand-alone users
iv. Sophisticated users
v. Specialized users
vi. System Analyst
Database Users and Administrators
i. Naive users:
✓Naive users or Parametric End Users are the unsophisticated who don’t have any DBMS knowledge but they
frequently use the data base applications in their daily life to get the desired results.
Example:
ATMs (Automated Teller Machine), Railway’s ticket booking users, Clerks in any bank etc.

ii. Application programmers:


✓They are responsible for developing the application programs or user interface.
✓They are the computer professionals who writes the code for the application programs.
✓These programs could be written in Programming languages such as Visual Basic, Java, .net, php, C, etc.
iii. Stand-alone users:
✓Those who are using database for personal usage.
✓There are many database packages are available for this type of users.
Database Users and Administrators
iv. Sophisticated users:
✓Sophisticated users can be engineers, scientists, business analyst, who are familiar with the database.
✓They interact with the system by writing SQL queries directly through the query processor.
✓They are the SQL programmers, who are going to deal directly with the database.
v. Specialized users:
✓They are also sophisticated users who write specialized database applications that do not fit into the traditional
data processing framework.
Example:
✓Expert System, Knowledge Based System, etc.
vi.System Analyst :
✓System Analyst is a user who analyzes the requirements of parametric end users. They check whether all the
requirements of end users are satisfied.
Database Users and Administrators
DATABASE ADMINISTRATORS:
✓Database Administrators coordinate all the activities of the database system. They have all the permissions and
also controls the 3 levels of database.
✓Tasks of DBA:
–Creating the schema
–Changing the schema
–Specifying integrity constraints
–Storage structure and access method definition
–Granting permission to other users.
–Monitoring performance
-Responsible for providing security to the data base
-Monitors the recovery and back up and provide technical support
Database Users and Administrators
Types of DBA:
✓Within larger organizations, DBA responsibilities typically are split into separate types of roles, Many different
types of DBAs exist, the most common types include :
❖System DBA
❖Database architect
❖Application DBA
❖Task-oriented DBA
❖Performance analyst
❖Data warehouse administrator
❖Cloud DBA
❖System DBA:
✓In this role, the focus is on technical details of how the database is installed, configured and modified. Typical tasks
include the following:
▪Installing new versions and ensuring appropriate storage and memory are available for the DBMS etc.
Database Users and Administrators
❖Database architect:
✓Primary responsibility is the design and implementation of new databases. Typical tasks include the following:
▪Translating logical data models into a physical database design
▪Analyzing data access requirements to ensure optimal database design
▪Creating backup and recovery strategies for new databases.
❖Application DBA:
✓Focus is on database design and the ongoing database support and administration for a specific application.
✓The application DBA is more likely an expert in writing and debugging complex SQL and will understand the best
ways to incorporate database requests into application programs.
Database Users and Administrators
❖Task-oriented DBA:
✓This specialized DBA focuses on a specific administrative task.
✓A backup-and-recovery DBA, for example, would be task-oriented to ensure the organization's databases are
recoverable, including creating backup plans, building and testing backup scripts, testing recovery scripts and driving
recovery tasks when required.
❖Performance analyst:
✓The performance analyst focuses entirely on monitoring and improving the performance of applications that
access databases.
❖Data warehouse administrator:
✓ This fully capable DBA has the knowledge and skills to monitor and support the data warehouse environment.
❖Cloud DBA:
✓The cloud DBA understands the services the cloud provider offers, including backup and security, to implement
databases in the cloud.
Database System Structure
Database System Structure
✓A database system is partitioned into 3-modules that deal with each of the responsibilities of the overall system.
✓The top part of the diagram refers to the various users of the database environment and their interfaces.
✓ The lower part shows the internals of the DBMS responsible for storage of data and processing of transactions.
✓The functional components of a database system can be broadly divided into three components:
1. Query processor
2. Storage manager
3. Disk Storage

1. Query Processor:
✓The query processor helps the database system simplify and facilitate access to data.
✓It interprets the requests (queries) received from end user via an application program into instructions.
✓The query processor components include:
i. DDL interpreter
ii. DML compiler
iii. Query evaluation engine
Database System Structure
i. DDL interpreter:
✓It processes the DDL statements into a set of table containing meta data .
ii. DML compiler:
✓It translates DML statements in a query language into low-level instructions that the query evaluation engine
understands, so that they can be executed.
✓A query can usually be translated into any of a number of alternative evaluation plans that all give the same
result.
✓The DML compiler also performs query optimization, that is, it picks the lowest cost evaluation plan from among
the alternatives.
iii. Query evaluation engine:
✓ It executes low-level instructions generated by the DML compiler.
Database System Structure
2. Storage Manager:
✓It is also known as Database Control System.
✓It is responsible for updating, storing, deleting, and retrieving data in the database.
✓It translates the various DML statements into low-level file-system commands.
✓ It maintains the consistency and integrity of the database by applying the constraints and executing the DCL
statements.
✓The Storage Manager components include:
i. Buffer manager
ii. File manager
iii. Authorization and Integrity Manager
iv. Transaction manager
Database System Structure
i. Buffer Manager:
✓ It is responsible for fetching data from disk storage into main memory, and deciding what data to cache in main
memory.
ii. File Manager:
✓It manages the file space and the data structure used to represent information in the database.
iii. Authorization and Integrity Manager:
✓ It ensures role-based access control, i.e,. checks whether the particular person is privileged to perform the
requested operation or not.
✓It checks the integrity constraints when the database is modified.
iv. Transaction Manager:
✓A transaction is a collection of operations that performs a single logical function in a database application.
✓It ensures that the database remains in the consistent state before and after the execution of a transaction.
✓It controls concurrent access by performing the operations in a scheduled way that it receives the transaction.
Database System Structure
3.Disk Storage:
✓It contains three components:
i. Data Files
ii. Data Dictionary
iii. Indices
i. Data Files:
✓ It stores the data.
ii. Data Dictionary:
✓ It contains the information about the structure of any database.
✓ It is the repository of information that governs the metadata.
iii. Indices:
✓ It provides faster retrieval of data item.
Database design
The design process consists of the following steps:

i. Determine the purpose of your database :

✓This helps prepare you for the remaining steps.

ii. Find and organize the information required :

✓Gather all of the types of information you might want to record in the database.

iii. Divide the information into tables :

✓Divide your information items into major entities or subjects . Each subject then becomes a table.

iv. Turn information items into columns :

✓Decide what information you want to store in each table. Each item becomes a field, and is displayed as a column

in the table.
Database design

v. Specify primary keys:

✓Choose each table’s primary key. The primary key is a column that is used to uniquely identify each row.

vi. Set up the table relationships :


✓Look at each table and decide how the data in one table is related to the data in other tables.

vii. Refine your design :


✓Analyze your design for errors. Create the tables and add a few records of sample data. See if you can get

the results you want from your tables. Make adjustments to the design, as needed.

viii. Apply the normalization rules :


✓Apply the data normalization rules to see if your tables are structured correctly.
Data Model
✓The Data Model gives us an idea of how the final system would look after it has been fully implemented.

✓It specifies the data items as well as the relationships between them.

✓These are often used to show how data is connected, stored, accessed, and changed.

✓Types of Data Models in DBMS

1. Hierarchical Model

2. Network Model

3. Entity-Relationship Model

4. Relational Model

5. Object-Oriented Data Model


Data Model
1. Hierarchical Model:

✓ This is one of the oldest models in a data model which was developed by IBM, in the 1950s.

✓ The Hierarchical Model was the first database management system model.

✓ It uses a hierarchical tree structure to organize the data.

✓ The hierarchy begins at the root, which contains root data, and then grows into a tree as child nodes are

added to the parent node.

✓ In this model, a child node will only have a single parent node.

✓ This model efficiently describes many real-world relationships like index of a book, food recipes, website

sitemaps, and so on.


Data Model
1. Hierarchical Model:
Data Model
1. Hierarchical Model:
Data Model
2 . Network Model:
✓ This is an extension of the Hierarchical model.
✓ It is fairly simple and easy to create.
✓ It uses a graph instead of a hierarchical tree.
✓ In this model data is organized more like a graph, and are allowed to have more than one parent node.
✓ Data is more related as more relationships are established in this database model.
✓ As the data is more related, hence accessing the data is also easier and fast.
✓ This was the most widely used database model, before Relational Model was introduced.
Data Model
2 . Network Model:
Data Model
3.E-R Model:
✓ER model stands for an Entity-Relationship model
✓It was developed by Peter Chen in 1976.
✓It’s a logical tool which is used for database design .
✓In ER modeling, the database structure is portrayed as a diagram.
✓ It represent the relationships into pictorial form to make it easier for different stakeholders to
understand.
✓ This model is good to design a database, which can then be turned into tables in relational model.
E-R Model
✓E-R Diagram has 3 main components
E-R Model
i.Entity-Type:
✓Entity-Type is denoted by the rectangle box.

✓An entity-type can be a real-world object either living or non-living like a person, place, concept, object, or
event.
Example:
✓In a school database, students, teachers, classes, and courses offered can be considered as entities.

Student
S1
Student S2
✓All the entities have their properties which are called attributes . s3

✓Collection of similar types of entities known as an entity set.


✓For example, a Student set may contain all the students.
E-R Model
Types of Entities:
i. Strong Entity
ii. Weak Entity
i. Strong Entity :
✓ It is represented using a single rectangle.
✓Strong entity are those entity types which has a key attribute.

✓In the above example, Roll_id identifies each element of the table uniquely and hence, we can say that
STUDENT is a strong entity type.
E-R Model
ii. Weak Entity :
✓The weak entity is represented by a double rectangle.

✓An entity that depends on another entity called a weak entity.


✓The weak entity doesn't contain any key attribute of its own.
E-R Model
ii. Attribute:
✓The attribute is used to describe the property of an entity.
✓Ellipse is used to represent an attribute.
Example:
✓id, age, contact number, name, etc. can be attributes of a student.

Types of Attributes:
i. Key attribute
ii. Composite attribute
iii. Multi-valued attribute
iv. Derived attribute
E-R Model
Types of Attributes
i. Key Attribute :
✓It is represented by an ellipse with the text underlined.
✓The attribute which uniquely identifies each entity in the entity set is called key attribute.
Example:
✓Roll_No will be unique for each student.
ii. Composite Attribute :
✓ An attribute that is composed of many other attributes is known as a composite attribute.
✓The composite attribute is represented by an ellipse, and those ellipses are connected with an ellipse.
E-R Model
iii. Multivalued Attribute :
✓An attribute can have more than one value.
✓The double oval is used to represent multivalued attribute.
Example:
✓student can have more than one phone number.
iv. Derived Attribute :
✓An attribute that can be derived from another attribute is known as a derived attribute.
✓It can be represented by a dashed ellipse.
✓A derived attribute is one whose value is dynamic and derived from another attribute.
Example:
✓A person's age changes over time and can be derived from another attribute like Date of birth.
E-R Model
iii. Relationship:
✓A relationship is used to describe the relation between entities.
✓Diamond or rhombus is used to represent the relationship.
✓Lines are used to link attributes to entity sets and entity sets to relationship sets.

Degree of a relationship set:


✓The number of entity sets that participate in a relationship is called as the degree of the relationship set.
i. Unary Relationship:
✓When there is only one entity set participating in a relation, the relationship is called as unary relationship.
✓For example, one person is married to only one person.
E-R Model
ii. Binary Relationship:
✓When there are two entities set participating in a relation, the relationship is called as binary relationship.
Example:
✓Student is enrolled in Course.

iii. n-ary Relationship:


✓When there are n entities set participating in a relation, the relationship is called as n-ary relationship.
E-R Model
Relationship set or cardinality:
✓Cardinality represents the number of times an entity of an entity set participates in a relationship
set.
✓The maximum no of relationships in which an entity can participate.

❖ Cardinality of employee :1

❖ Cardinality of Department : N
E-R Model
Relationship set or cardinality:
Types of cardinality in between tables are:
✓one-to-one
✓one-to-many
✓many-to-one
✓many-to-many
E-R Model
Types of relationship:
i. One-to-One Relationship :
✓When a single instance of an entity is associated with a single instance of another entity then it is called
one to one relationship.
Example:
✓A male can marry to one female and a female can marry to one male. So the relationship will be one to
one.

Example:
✓A person has only one passport and a passport is given to one person.
E-R Model
ii. One-to-many relationship :
✓When only one instance of the entity on the left, and more than one instance of an entity on the right associates
with the relationship then this is known as a one-to-many relationship.
Example:
✓One Scientist can invent many inventions, but the invention is done by the only specific scientist.

✓One customer can place many orders


E-R Model
iii. Many-to-one relationship:
✓When more than one instance of the entity on the left, and only one instance of an entity on the right
associates with the relationship then it is known as a many-to-one relationship.
Example:
✓Many students can study in a single college but a student cannot study in many colleges at the same time.

✓Student enrolls for only one course, but a course can have many students.
E-R Model
iv. Many-to-many relationship :
✓When more than one instance of the entity on the left, and more than one instance of an entity on the right
associates with the relationship then it is known as a many-to-many relationship.
Example:
✓ student can be assigned to many projects and a project can be assigned to many students.

✓Employee can assign by many projects and project can have many employees.
Data Model
ER DIAGRAM FOR UNIVERSITY DATABASE
ER DIAGRAM FOR COMPANY DATABASE
Data Model
iv. Relational Model:
✓ This model was introduced by E.F Codd in 1970, and since then it has been the most widely used
database model.
✓ In this model, data is organized in two-dimensional tables and the relationship is maintained by
storing a common field.
✓ The basic structure of data in the relational model is tables.
✓ All the information related to a particular type is stored in rows of that table.
✓ Hence, tables are also known as relations in relational model.
✓ Popular Relational Database Management Systems:
1) IBM – DB2 and Informix Dynamic Server
2) Oracle – Oracle and RDB
3) Microsoft – SQL Server and Access
Data Model
iv. Relational Model:
Data Model
v.Object-Oriented Data Model:
✓ In this model both the data and the relationship are contained in a single structure that is known as an object in
this model.
✓ We can now store audio, video, pictures, and other types of data in databases, Although you can store video and
audio in relational DB, it is advised not to store them in the relational database.
Example:
✓ The Employee and Department are the two objects .

✓ Each object’s data and the relationships are there in a single unit.
✓ Here, the attributes of the employee, such as Name and Job_title, as well as
the methods that will be performed by that object, are all kept in a single
object.
✓ The two objects are linked by a common attribute, i.e., Department_id, as
well as communication between them will be accomplished by this common
id.
Introduction to the relational model
✓ In this model, the data is organized into a collection of two-dimensional inter-related tables, also known as

relations.

✓ It makes data sorting and data access easier.

✓ Provides a standard way to organize data in databases.

✓ This database consists of various components .These include:


i. Relation
ii. Tuple
iii. Attribute/Field
iv. Attribute Domain
v. Degree
vi. Cardinality
vii. Relational Schema
viii. Relational Instance
ix. Relation Key
Relational Model Concepts
1. Relation : Two-dimensional table used to store a collection of data elements.

2. Tuple : Row of the relation, depicting a real-world entity.

3. Attribute/Field : Column of the relation, depicting properties that define the relation.

4. Attribute Domain : Set of pre-defined atomic values that an attribute can take i.e., it describes the legal
values that an attribute can take.

5. Degree : It is the total number of attributes present in the relation.

6. Cardinality : It specifies the number of entities involved in the relation i.e., it is the total number of
rows present in the relation.

7. Relational Schema : It is the logical blueprint of the relation i.e., it describes the design and the structure of
the relation. It contains the table name, its attributes, and their types.
TABLE_NAME(ATTRIBUTE_1 TYPE_1, ATTRIBUTE_2 TYPE_2, ...)
Relational Model Concepts
7 Relational Instance : It is the collection of records present in the relation at a given time.

8 Relation Key : It is an attribute or a group of attributes that can be used to uniquely identify an entity
in a table or to determine the relationship between two tables. Relation keys can be of 7
different types:

✓ Keys play an important role in the relational database.


✓ It is used to uniquely identify any record or row of data from the table. It is also used to establish and identify
relationships between tables.
Constraints in Relational Model
✓ Relational models make use of some rules to ensure the accuracy and accessibility of the data. These
rules or constraints are known as Relational Integrity Constraints.
✓ These constraints are checked before performing any operation like insertion, deletion, or updation
on the data present in a relational database.
✓ These constraints include:
i. Domain Constraint : It specifies that every attribute is bound to have a value that lies inside
a specific range of values.
ii. Key Constraint : It states that every relation must contain an attribute or a set of attributes
that can uniquely identify a tuple in that relation.
iii. Referential Integrity Constraint : It is defined between two inter-related tables. It states
that if a given relation refers to a key attribute of a different or same table.
Key constraints in DBMS
✓ Constraints are the rules that are to be followed while entering data into columns of the database table.
✓ Constraints ensure that the data entered by the user into columns must be within the criteria specified by the
condition.
✓ We have 10- types of key constraints in DBMS
1. Not Null
2. Unique
3. Default
4. Check
5. Super key
6. Candidate key
7. Primary key
8. Foreign key
9. Composite key
10. Alternate key
Key constraints in DBMS
1. Not Null:
✓ Once not null is applied to a particular column, you cannot enter null values to that column.
✓ A not null constraint cannot be applied at table level

Example:

Create table student ( Roll_No number(4) Not null, name varchar2(10) , Age number(4), Phone number(10));

✓ In the above example we have applied not null Roll_No column,whenever a record is entered using insert statement
Roll_No column should contain a value other than null.
Key constraints in DBMS
2. Unique:
✓ Some times we need to maintain only. Unique data in the column of a database table, this is possible by
using a Unique constraint.
✓ Unique constraint ensures that all values in a column are Unique.

Example:

Create table student ( Roll_No number(4) Unique, name varchar2(10) , Age number(4), Phone number(10));

✓ In the above example, as we have used unique constraint on ID column we are not supposed to enter the data
that is already present, simply no two ID values are same.
Key constraints in DBMS
3. Default:
✓ Default in SQL is used to add default data to the columns.
✓ When a column is specified as default with same value then all the rows will use the same value i.e., each and
every time while entering the data we need not enter that value.
✓ But default column value can be customised i.e., it can be over ridden when inserting a data for that row
based on the requirement.

Example:
Create table EMPLOYEE (id_no number(10) Not null, name varchar (25) Not null, company varchar (25) Default abc);

✓ As a result, whenever you insert a new row each time you need not enter a value for this default column that
is entering a column value for a default column is optional.
Key constraints in DBMS
4. Check:
✓ Check constraint ensures that the data entered by the user for that column is within the range of values or
possible values specified.

Example:
Create table STUDENT (Roll_No number(4) Unique, name varchar (25) not null, age number(2) check(age>=18));

✓ As we have used a check constraint as (age>=18) which means value entered by user for this age column while
inserting the data must be less than or equal to 18
Keys
5. Super Key:
✓ A super key is a set of attributes that can identify each tuple uniquely in the given relation.
✓ Super key may consist of any number of attributes.
Example:
✓ Consider the following Student schema-

Student ( roll , name , gender , age , address , class , section )

✓ Given below are the examples of super keys since each set can uniquely identify each student in
the Student table-
-( roll , name , gender , age , address , class , section )
-( class , section , roll )
-(class , section , roll , gender )
-( name , address )
Keys
6. Candidate Key:
✓ A set of minimal attribute(s) that can identify each tuple uniquely in the given relation is called as a
candidate key.
✓ Candidate Key is a super key with no repeated attributes.
✓ The Primary key should be selected from the candidate keys.
Example:
✓ Consider the following Student schema-

Student ( roll , name , gender , age , address , class , section )

✓ Given below are the examples of candidate keys since each set consists of minimal attributes required
to identify each student uniquely in the Student table-
-( class , section , roll )
-( name , address )
Keys
6. Candidate Key:
✓ The value of candidate key must always be unique.
✓ The value of candidate key can never be NULL.
✓ It is possible to have multiple candidate keys in a relation.
Keys
7.Primary Key :
✓ A primary key is a candidate key that the database designer selects while designing the database.
✓ It is a column or group of columns in a table that uniquely identify every row in that table.
✓ The Primary Key can’t be a duplicate meaning the same value can’t appear more than once in
the table.
Rules for defining Primary key:
✓ The value of primary key can never be NULL.
✓ The value of primary key must always be unique.
✓ The values of primary key can never be changed i.e. no updation is possible.
✓ The value of primary key must be assigned when inserting a record.
✓ A relation is allowed to have only one primary key.
Keys
Creating Primary Key :
✓ A particular column is made as a primary key column by using the primary key keyword
followed by the column name.
Example:

Create table EMP (Roll_No number(4), name varchar2(20), age number(4), gpa varchar2(10), Primary key (Roll_No));

✓ Here we have used the primary key on ID column then ID column must contain unique values
i.e., one ID cannot be used for another student.
Keys
8.Foreign Key:
✓ The foreign key constraint is a column or list of columns which points to the primary key column of
another table.
✓ The main purpose of the foreign key is only those values are allowed in the present table that will
match to the primary key column of another table.
Keys

From the above two tables, COURSE_ID is a primary key of the table STUDENT_DETAILS and also behaves as a foreign key
in STUDENT_MARKS.
Example:
(Reference Table)

Create table STUDENT_DETAILS (ROLL_NO number(10), NAME varchar2 (25), COURSE_ID varchar (10), primary key (COURSE_ID));

(Child table)

Create table STUDENT_MARKS (COURSE_ID varchar (10), MARKS number(10), references STUDENT_DETAILS (COURSE_ID ));
Keys
NOTE:
✓ Foreign key references the primary key of the table.
✓ Foreign key can take only those values which are present in the primary key of the referenced relation.
✓ Foreign key may have a name other than that of a primary key.
✓ Foreign key can take the NULL value.
✓ There is no restriction on a foreign key to be unique.
✓ In fact, foreign key is not unique most of the time.
✓ Referenced relation may also be called as the master table or primary table.
✓ Referencing relation may also be called as the foreign table.
Keys
Keys
9. Alternate Key:
✓ A table can have multiple choices for a primary key but only one can be set as the primary key. All the
keys which are not primary key are called an Alternate Key.
✓ Candidate keys that are left unimplemented or unused after implementing the primary key are called as
alternate keys.
Keys
10. Composite Key:
✓ Sometimes, a table might not have a single column/attribute that uniquely identifies all the records of a table. In
order to uniquely identify rows of a table, combination of two or more columns/attributes can be used.
✓ COMPOSITE KEY is a combination of two or more columns that uniquely identify rows in a table. The combination of
columns guarantees uniqueness, though individually uniqueness is not guaranteed.
✓ Whenever a primary key consists of more than one attribute, it is known as a composite key.
✓ This key is also known as Concatenated Key.
Keys
Relational algebra
✓ Relational database systems are expected to be equipped by a query language that can assist its user to

query the database instances.

✓ There are two kinds of query languages, relational algebra and relational calculus.

✓ Relational algebra is a procedural query language, which takes instances of relations as input and yields

instances of relations as output.

✓ Fundamental operations of Relational algebra:


i. Select
ii. Project
iii. Union
iv. Set different
v. Cartesian product
vi. Rename
Relational algebra operations
i.Select Operation (σ) Syntax

✓ Selects tuples that satisfy the given predicate from a relation. σ p (r)
✓ Where p stands for selection predicate and r stands for relation. p is prepositional logic formulae
which may use connectors like and, or and not. These terms may use relational operators like: =, ≠,
≥, < , >, ≤.

Example Output :
σsubject="database" (Books)) Selects tuples from books where subject is
'database'.

Example Output :
σ subject="database" and price="450" (Books) Selects tuples from books where subject is 'database' and
'price' is 450.
Relational algebra operations
ii.Project Operation (∏):
✓ Projects column(s) that satisfy given predicate.

Syntax

∏A1, A2, An (r)

✓ Where a1, a2 , an are attribute names of relation r. Duplicate rows are automatically eliminated, as
relation is a set.

Example
∏subject, author (Books)

Output :
Selects and projects columns named as subject and author from relation Books.
Relational algebra operations
iii.Union Operation (∪):
Syntax
✓ Union operation performs binary union between two given
relations and is defined as: r ∪ s = { t | t ∈ r or t ∈ s}
✓ Where r and s are either database relations or relation
result set (temporary relation).
✓ For a union operation to be valid, the following conditions
must hold: Example
✓ r, s must have same number of attributes. ∏ author (Books) ∪ ∏ author (Articles)

✓ Attribute domains must be compatible.


✓ Duplicate tuples are automatically eliminated.
Output :
Projects the name of author
who has either written a book
or an article or both.
Relational algebra operations
iv. Set Difference ( − ):
✓ The result of set difference operation is tuples which present in one relation but are not in the
second relation.
Syntax

r−s
✓ Finds all tuples that are present in r but not s.

Example
∏ author (Books) − ∏ author (Articles)

Output :
Results the name of authors who has written books but not articles.
Relational algebra operations
v.Cartesian Product (Χ):
✓ Combines information of two different relations into one.

Syntax

rΧs Syntax

r Χ s = { q t | q ∈ r and t ∈ s}
✓ Where r and s are relations and there output will be defined as:

Example
∏ author = 'tutorialspoint'(Books Χ Articles))

Output :
yields a relation as result which shows all books and articles written by tutorialspoint.
Relational algebra operations
vi.Rename operation ( ρ ):
✓ Results of relational algebra are also relations but without any name.
✓ The rename operation allows us to rename the output relation. rename operation is denoted with
small greek letter rho ρ

Syntax

ρ x (E)
✓ Where the result of expression E is saved with name of x.

Example
ρ x (E)
Relational Calculus
✓ Relational Calculus is non-procedural query language, that is, it tells what to do but never explains the
way, how to do it. Relational calculus exists in two forms:
i. Tuple relational calculus (TRC)
ii. Domain relational calculus (DRC)
Relational Calculus
i.Tuple relational calculus (TRC):
✓ Filtering variable ranges over tuples.

Syntax

{ T | Condition }
✓ Returns all tuples T that satisfies condition.

Example Output:
{ T.name | Author(T) AND T.article = 'database' } returns tuples with 'name' from Author
who has written article on 'database'.

✓ TRC can be quantified also. We can use Existential ( ∃ )and Universal Quantifiers ( ∀ ).

Example Output :
{ R| ∃T ∈ Authors(T.article='database' AND R.name=T.name)} The query will yield the same result as
the previous one
Relational Calculus
ii. Domain relational calculus (DRC) :
✓ In DRC the filtering variable uses domain of attributes instead of entire tuple values (as done in
TRC, mentioned above).
Syntax
{ a1, a2, a3, ..., an | P (a1, a2, a3, ... ,an)}

✓ where a1, a2 are attributes and P stands for formulae built by inner attributes.

Example
{< article, page, subject > | ∈ TutorialsPoint ∧ subject = 'database'}

Output:
Yields Article, Page and Subject from relation TutorialsPoint where Subject is database.
‘U’ T

K H

N A

You might also like