0% found this document useful (0 votes)
15 views35 pages

BILAL DBMS UNIT-1 Notes

The document provides an introduction to database management systems (DBMS). It discusses key concepts such as data, information, databases, database management systems, and their functions and advantages. It contrasts database systems with traditional file systems, noting issues like data redundancy, integrity, and access with file systems. It also lists some common applications of databases like banking, airlines, universities, and more. Finally, it discusses views of data in a DBMS and the concept of data abstraction which hides internal details from users.
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)
15 views35 pages

BILAL DBMS UNIT-1 Notes

The document provides an introduction to database management systems (DBMS). It discusses key concepts such as data, information, databases, database management systems, and their functions and advantages. It contrasts database systems with traditional file systems, noting issues like data redundancy, integrity, and access with file systems. It also lists some common applications of databases like banking, airlines, universities, and more. Finally, it discusses views of data in a DBMS and the concept of data abstraction which hides internal details from users.
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/ 35

DBMS UNIT-I

Introduction and Data Base Design: Introduction to DBMS, applications of DBMS, database systems
versus file systems, view of data, Database users and administrators, database system structure.
Database Design- E-R diagrams, entities, attributes and entity sets, relationships and relationship sets,
additional features of the E-R model. The Relational Model: Introduction to the relational model,
logical database design: E-R to relational, relational algebra operations and basic queries, relational
calculus operators and basic queries.

1. Introduction to Database Management System


1.1 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.

1.2 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.

1.3 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.

1.4 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.

1.5 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.

Mohammad Bilal J, Dept of IT,VCE


DBMS UNIT-I

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.

1.6 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.

1.7 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.

2.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 For purchases on credit cards and generation of monthly statements.
transactions

Mohammad Bilal J, Dept of IT,VCE


DBMS UNIT-I

5. Telecommunication For keeping records of calls made, generating monthly bills, maintaining
balances on prepaid calling cards, and storing information about the
communication networks.

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 For reservations and schedule information.


Reservation
Systems

3.Database System Vs File System

File Management System Database Management System

It is easy-to-use system to store general files It is used when security constraints are
which require less security and constraints. high.

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 User is unaware of physical address where
files to access data . data is stored.

Security is low. Security is high.

It stores unstructured data It stores structured data

Mohammad Bilal J, Dept of IT,VCE


DBMS UNIT-I

3.1 Drawbacks of File System:


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

Data redundancy and inconsistency:


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

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.

Integrity Problems:
-Hard to add new constraints or change existing ones.

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.

Concurrent access Anomalies:


-Data accessed by multiple users.

-Uncontrolled concurrent accesses can lead to inconsistencies.

Security Problems:
-Not every user of the database system should be able to access all the data.

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

✓ The top level of that architecture is “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 the user.

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

▪ Data Abstraction

▪ Instance and Schema.


View Level

Logical Level

Physical
Level
Mohammad Bilal J, Dept of IT,VCE
DBMS UNIT-I

4.1 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.

✓ There are three levels of abstractions

4.1.1 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.

4.1.2 Logical level abstraction:


✓ It describes what data is stored in database.

4.1.3 View level abstraction:


✓ This level describes the user interaction with database system.

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.

Mohammad Bilal J, Dept of IT,VCE


DBMS UNIT-I

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.

4.2 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

Mohammad Bilal J, Dept of IT,VCE


DBMS UNIT-I

4.2.1 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.

4.2.2 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.

4.2.3 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.

4.3 Data independence


The ability to modify a schema definition in one level with out affecting a schema definition in next
higher level is called data independence.

Physical data independence: The ability to modify the physical schema without changing
logical schema

Logical data independence: The ability to modify the logical or conceptual schema without
changing application programs.

In general, the interfaces between the various levels


and components should be well defined so that
changes in some parts do not seriously influence
others

4.4 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.

Mohammad Bilal J, Dept of IT,VCE


DBMS UNIT-I

✓ 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.

5.Database Users and Administrators


5.1 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

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.

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.

Mohammad Bilal J, Dept of IT,VCE


DBMS UNIT-I

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.

5.2 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

5.2.1 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.

Mohammad Bilal J, Dept of IT,VCE


DBMS UNIT-I

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.

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.

Mohammad Bilal J, Dept of IT,VCE


DBMS UNIT-I

6.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:

▪ Query processor

▪ Storage manager

▪ Disk Storage

6.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:

▪ DDL interpreter

▪ DML compiler

▪ Query evaluation engine

Mohammad Bilal J, Dept of IT,VCE


DBMS UNIT-I

DDL interpreter:
✓ It processes the DDL statements into a set of table containing meta data .

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.

Query evaluation engine:


✓ It executes low-level instructions generated by the DML compiler.

6.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:

▪ Buffer manager

▪ File manager

▪ Authorization and Integrity Manager

▪ Transaction manager

Buffer Manager:
✓ It is responsible for fetching data from disk storage into main memory, and deciding
what data to cache in main memory.

File Manager:
✓ It manages the file space and the data structure used to represent information in the
database.

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.

Transaction Manager:
✓ A transaction is a collection of operations that performs a single logical function in a
database application.

Mohammad Bilal J, Dept of IT,VCE


DBMS UNIT-I

✓ 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.

6.3 Disk Storage:


✓ It contains three components:

▪ Data Files

▪ Data Dictionary

▪ Indices

Data Files:
It stores the data.

Data Dictionary:
It contains the information about the structure of any database.

It is the repository of information that governs the metadata.

Indices:
It provides faster retrieval of data item.

7.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.

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.

Mohammad Bilal J, Dept of IT,VCE


DBMS UNIT-I

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.

8.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
i. Hierarchical Model
ii. Network Model
iii. Entity-Relationship Model
iv. Relational Model
v. Object-Oriented Data Model

8.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.

Mohammad Bilal J, Dept of IT,VCE


DBMS UNIT-I

8.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.

8.3 E-R Model:


✓ ER model sta9.nds 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 Diagram has 3 main components

Mohammad Bilal J, Dept of IT,VCE


DBMS UNIT-I

8.3.1 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
✓ All the entities have their properties which are called attributes .
S2
✓ Collection of similar types of entities known as an entity set.
s3
✓ For example, a Student set may contain all the students.

Types of Entities:
▪ Strong Entity

▪ Weak Entity

Strong Entity :
✓ It is represented using a single rectangle.

✓ Strong entity are those entity types which has a key attribute.

Mohammad Bilal J, Dept of IT,VCE


DBMS UNIT-I

✓ 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.

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.

8.3.2 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:
▪ Key attribute

▪ Composite attribute

▪ Multi-valued attribute

▪ Derived attribute

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.

Mohammad Bilal J, Dept of IT,VCE


DBMS UNIT-I

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.

9.3.3 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

Mohammad Bilal J, Dept of IT,VCE


DBMS UNIT-I

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.

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

Relationship set or cardinality:


Types of cardinality in between tables are:

✓ one-to-one

✓ one-to-many

✓ many-to-one

✓ many-to-many

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.

Mohammad Bilal J, Dept of IT,VCE


DBMS UNIT-I

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.

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

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.

Mohammad Bilal J, Dept of IT,VCE


DBMS UNIT-I

✓ Student enrolls for only one course, but a course can have many students.

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.

Mohammad Bilal J, Dept of IT,VCE


DBMS UNIT-I

ER DIAGRAM FOR UNIVERSITY DATABASE

Mohammad Bilal J, Dept of IT,VCE


DBMS UNIT-I

ER DIAGRAM FOR COMPANY DATABASE

8.4. 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:

❖ IBM – DB2 and Informix Dynamic Server

❖ Oracle – Oracle and RDB

❖ Microsoft – SQL Server and Access

Mohammad Bilal J, Dept of IT,VCE


DBMS UNIT-I

8.5. 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.

9. 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

Mohammad Bilal J, Dept of IT,VCE


DBMS UNIT-I

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 Set of pre-defined atomic values that an attribute can take i.e., it describes
Domain 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 It is the logical blueprint of the relation i.e., it describes the design and the
Schema structure of the relation. It contains the table name, its attributes, and their
types.

TABLE_NAME(ATTRIBUTE_1 TYPE_1, ATTRIBUTE_2 TYPE_2, ...)

7 Relational It is the collection of records present in the relation at a given time.


Instance
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:

9.1 Relational Model Concepts:

✓ 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.

9.1.1 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:

Domain Constraint: It specifies that every attribute is bound to have a value that lies inside a
specific range of values.

Mohammad Bilal J, Dept of IT,VCE


DBMS UNIT-I

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.

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.

9.1.2 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

i. Not Null

ii. Unique

iii. Default

iv. Check

v. Super key

vi. Candidate key

vii. Primary key

viii. Foreign key

ix. Composite key

x. Alternate key

i. 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.

Mohammad Bilal J, Dept of IT,VCE


DBMS UNIT-I

ii. 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.

iii. 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.

iv. 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));

Mohammad Bilal J, Dept of IT,VCE


DBMS UNIT-I

✓ 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.

v. 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:
Student ( roll , name , gender , age , address , class , section )

✓ Consider the following Student schema-

✓ 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 )

vi. 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:

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

✓ Consider the following Student schema-

✓ 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 )

✓ The value of candidate key must always be unique.

Mohammad Bilal J, Dept of IT,VCE


DBMS UNIT-I

✓ The value of candidate key can never be NULL.

✓ It is possible to have multiple candidate keys in a relation.

vii.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.

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.

Mohammad Bilal J, Dept of IT,VCE


DBMS UNIT-I

viii.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.

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));

Create table STUDENT_MARKS (COURSE_ID varchar (10), MARKS number(10), references STUDENT_DETAILS (COURSE_ID ));

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.

Mohammad Bilal J, Dept of IT,VCE


DBMS UNIT-I

ix. 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.

x. 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.

Mohammad Bilal J, Dept of IT,VCE


DBMS UNIT-I

10.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

10.1 Select Operation (σ):


✓ Selects tuples that satisfy the given predicate from a relation.

✓ 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: =, ≠, ≥, < , >, ≤.

Syntax Example

σ (r) σsubject="database" (Books))


p

Output : Selects tuples from books where subject is 'database'.

Example
σ subject="database" and price="450" (Books)

Output : Selects tuples from books where subject is 'database' and 'price' is 450.

10.2 Project Operation (∏):


✓ Projects column(s) that satisfy given predicate.

Syntax

∏ (r)
A1, A2, An

Mohammad Bilal J, Dept of IT,VCE


DBMS UNIT-I

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

Example
∏ (Books)
subject, author

Output :

Selects and projects columns named as subject and author from relation Books.

10.3 Union Operation (∪):


✓ Union operation performs binary union between two given relations and is defined as:

✓ 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:

✓ r, s must have same number of attributes.

✓ Attribute domains must be compatible.

✓ Duplicate tuples are automatically eliminated.

Syntax Example

r ∪ s = { t | t ∈ r or t ∈ s} ∏ author (Books) ∪ ∏ author (Articles)

Output :

Projects the name of author who has either written a book or an article or both.

10.4 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.

Mohammad Bilal J, Dept of IT,VCE


DBMS UNIT-I

10.5 Cartesian Product (Χ):


✓ Combines information of two different relations into one.

Syntax Syntax

rΧs r Χ s = { q t | q ∈ r and t ∈ s}

Example
∏ author = 'Raghu Ram Krishna'(Books Χ Articles))

Output :

yields a relation as result which shows all books and articles written by Raghu Ram Krishna'.

10.6 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 ρ

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

Syntax Example

ρ (E) ρ x (E)
x

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

11. 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)

11.1 Tuple relational calculus (TRC):


✓ Filtering variable ranges over tuples.

Syntax Example

{ T | Condition } { T.name | Author(T) AND T.article = 'database' }

Mohammad Bilal J, Dept of IT,VCE


DBMS UNIT-I

✓ Returns all tuples T that satisfies condition.

Output: 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
{ R| ∃T ∈ Authors(T.article='database' AND R.name=T.name)}

Output : The query will yield the same result as the previous one.

11.2 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 > | ∈ Technology ∧ subject = 'database'}

Output: Yields Article, Page and Subject from relation Technology where Subject is database.

Mohammad Bilal J, Dept of IT,VCE

You might also like