0% found this document useful (0 votes)
460 views38 pages

RDBMS Unit - I

1) The document discusses concepts related to relational database management systems including data, databases, DBMS, file systems, and advantages of DBMS over file systems. It provides examples of DBMS like MySQL, Oracle, and SQL Server. 2) Key characteristics of DBMS are described such as storing data in tables, reducing data redundancy, maintaining data consistency, supporting multiple users and queries. Advantages include improved data sharing, security, integration and access. 3) The differences between file-based and database approaches are explained. Advantages of DBMS over file systems are improved data sharing, security, integration and access. Disadvantages of DBMS include increased costs, management complexity and needing frequent upgrades.

Uploaded by

serboyka18
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)
460 views38 pages

RDBMS Unit - I

1) The document discusses concepts related to relational database management systems including data, databases, DBMS, file systems, and advantages of DBMS over file systems. It provides examples of DBMS like MySQL, Oracle, and SQL Server. 2) Key characteristics of DBMS are described such as storing data in tables, reducing data redundancy, maintaining data consistency, supporting multiple users and queries. Advantages include improved data sharing, security, integration and access. 3) The differences between file-based and database approaches are explained. Advantages of DBMS over file systems are improved data sharing, security, integration and access. Disadvantages of DBMS include increased costs, management complexity and needing frequent upgrades.

Uploaded by

serboyka18
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/ 38

RDBMS UNIT - I III SEM CA

__________________________________________
RELATIONAL DATABASE MANAGEMENT
UNIT-I
SYLLABUS
BASIC CONCEPTS: Database Management System - File based system - Advantages of DBMS over file-
based system - Database Approach - Logical DBMS Architecture - Three level architecture of DBMS or
logical DBMS architecture - Need for three level architecture - Physical DBMS Architecture - Database
Administrator (DBA) Functions & Role - Data files indices and Data Dictionary - Types of Database.
Relational and ER Models: Data Models - Relational Model – Domains - Tuple and Relation - Super
keys - Candidate keys - Primary keys and foreign key for the Relations - Relational Constraints - Domain
Constraint - Key Constraint - Integrity Constraint - Update Operations and Dealing with Constraint
Violations - Relational Operations - Entity Relationship (ER) Model – Entities – Attributes –
Relationships - More about Entities and Relationships - Defining Relationship for College Database -
E-R Diagram - Conversion of E-R Diagram to Relational Database.

1) WHAT IS DATA AND DATABASE?


A) Data is nothing but facts and statistics stored or free flowing over a network, generally it's raw and
unprocessed. This “data” is used in a variety of forms of text, numbers, media and many more. Data
becomes information when it is processed, turning it into something meaningful.

A database is an organized collection of data, so that it can be easily accessed and managed. You
can organize data into tables, rows, columns, and index it to make it easier to find relevant
information.

The main purpose of the database is to operate a large amount of information by storing,
retrieving, and managing data. There are many databases available like MySQL, Sybase, Oracle,
MongoDB, SQL Server, etc.

Modern databases are managed by the database management system (DBMS).

SQL or Structured Query Language is used to operate on the data stored in a database. SQL
depends on relational algebra and tuple relational calculus.

The major components of the Database are:

• Hardware : This consists of a set of physical electronic devices such as I/O devices, storage
devices and many more. It also provides an interface between computers and real-world systems.
• Software : This is the set of programs that are used to control and manage the overall Database.
It also includes the DBMS software itself. The Operating System, the network software being
used to share the data among the users, the application programs used to access data in the
DBMS.
• Data : Database Management System collects, stores, processes, and accesses data. The
Database holds both the actual or operational data and the metadata.

SHWETA K/SWAPNA A Page 1


RDBMS UNIT - I III SEM CA
__________________________________________
2) What is DBMS?
A) DBMS is a software that allows creation, definition and manipulation of database, allowing users
to store, process and analyze data easily. DBMS provides us with an interface or a tool, to perform
various operations like creating database, storing data in it, updating data, creating tables in the
database and a lot more.
DBMS also provides protection and security to the databases. It also maintains data consistency in
case of multiple users.
Here are some examples of popular DBMS used these days:

• MySql
• Oracle
• SQL Server
• IBM DB2
• PostgreSQL
• Amazon SimpleDB (cloud based) etc.

Characteristics of Database Management System (DBMS)


A database management system has following characteristics:

1. Data stored into Tables: Data is stored into tables, created inside the database. You can
easily understand what type of data is stored where by looking at all the tables created in a
database.
2. Reduced Redundancy:Unnecessary repetition of data in database was a big problem. But
DBMS follows Normalisation which divides the data in such a way that repetition is
minimum.
3. Data Consistency: On Live data, i.e. data that is being continuosly updated and added,
maintaining the consistency of data can become a challenge. But DBMS handles it all by itself.
4. Support Multiple user and Concurrent Access: DBMS allows multiple users to work on
it(update, insert, delete data) at the same time and still manages to maintain the data
consistency.
5. Query Language: DBMS provides users with a simple Query language, using which data can
be easily fetched, inserted, deleted and updated in a database.
6. Security: The DBMS also takes care of the security of data, protecting the data from un-
authorised access.
7. DBMS supports transactions, which allows us to better handle and manage data integrity in
real world applications where multi-threading is extensively used.

Q:2 WHAT IS FILE BASED SYSTEM OR FILE SYSTEM?


A) File based systems is also called a traditional based approach in which a decentralized approach A
file system is a technique of arranging the files in a storage medium like a hard disk, pen drive, DVD,
etc. It helps you to organize the data and allows easy retrieval of files when they are required. It mostly
consists of different types of files like mp3, mp4, txt, doc, etc. that are grouped into directories.

SHWETA K/SWAPNA A Page 2


RDBMS UNIT - I III SEM CA
__________________________________________
A file system enables you to handle the way of reading and writing data to the storage medium. It is
directly installed into the computer with the Operating systems such as Windows and Linux.

In the above figure: Consider an example of a student's file system. The student file will contain
information regarding the student (i.e. roll no, student name, course etc.). Similarly, we have a subject
file that contains information about the subject and the result file which contains the information
regarding the result. Some fields are duplicated in more than one file, which leads to data redundancy.
So to overcome this problem, we need to create a centralized system, i.e. DBMS approach.

DBMS:A database approach is a well-organized collection of data that are related in a meaningful way
which can be accessed by different users but stored only once in a system. The various operations
performed by the DBMS system are: Insertion, deletion, selection, sorting etc.

In the above figure,duplication of data is reduced due to centralization of data.

3) What is DBMS? EXPLAIN ADVANTAGES OF DBMS OVER FILE SYSTEM? and


disadvantages of DBMS.
A) DBMS is a software that allows creation, definition and manipulation of database, allowing users
to store, process and analyze data easily. DBMS provides us with an interface or a tool, to perform
various operations like creating database, storing data in it, updating data, creating tables in the
database and a lot more.

SHWETA K/SWAPNA A Page 3


RDBMS UNIT - I III SEM CA
__________________________________________
Advantages of Database Management System (DBMS)

1. Improved data sharing: The DBMS helps to create an environment in which end users have
better access to more and better-managed data.

2. Improved data security: The more users access the data, the greater the risks of data security
breaches. A DBMS provides a framework for better enforcement of data privacy and security policies.

3. Better data integration: Wider access to well-managed data promotes an integrated view of
the organization’s operations and a clearer view of the big picture

4. Minimized data inconsistency: Data inconsistency exists when different versions of the same
data appear in different places. The probability of data inconsistency is greatly reduced in a properly
designed database.

5. Improved data access: The DBMS makes it possible to produce quick answers to queries.

6. Improved decision making: Better-managed data and improved data access make it possible
to generate better-quality information, on which better decisions are based.

7. Increased end-user productivity: The availability of data, combined with the tools that
transform data into usable information, empowers end users to make quick, informed decisions that
can make the difference between success and failure in the global economy.

8. Minimized Data redundancy: DBMS follows Normalization which divides the data in such a
way that repetition is minimum.

Disadvantages of Database Management System (DBMS):


Although the database system yields considerable advantages over previous data management
approaches, database systems do carry significant disadvantages. For example:

1. Increased costs: The cost of maintaining the hardware, software, and personnel required to
operate and manage a database system can be substantial. Training, licensing, and regulation
compliance costs are often overlooked when database systems are implemented.

2. Management complexity: Database systems interface with many different technologies and
have a significant impact on a company’s resources and culture. Given the fact that database systems
hold crucial company data that are accessed from multiple sources, security issues must be assessed
constantly.

3. Maintaining currency: To maximize the efficiency of the database system, you must keep your
system current. Therefore, you must perform frequent updates and apply the latest patches and
security measures to all components.

4. Frequent upgrade/replacement cycles: DBMS vendors frequently upgrade their products by


adding new functionality. the upgrades themselves cost money, but it also costs trained database
users and administrators to properly use and manage the new features.

SHWETA K/SWAPNA A Page 4


RDBMS UNIT - I III SEM CA
__________________________________________

Q:4 Difference between DBMS and File systems:

Basis DBMS Approach File System Approach

Meaning DBMS is a collection of data. In The file system is a collection of data.


DBMS, the user is not required to In this system, the user has to write
write the procedures. the procedures for managing the
database.

Sharing of data Due to the centralized approach, data Data is distributed in many files, and
sharing is easy. it may be of different formats, so it
isn't easy to share data.

Security and DBMS provides a good protection It isn't easy to protect a file under the
Protection mechanism. file system.

Recovery DBMS provides a crash recovery The file system doesn't have a crash
Mechanism mechanism, i.e., DBMS protects the mechanism, i.e., if the system crashes
user from system failure. while entering some data, then the
content of the file will be lost.

Concurrency DBMS takes care of Concurrent In the File system, concurrent access
Problems access of data using some form of has many problems like redirecting
locking. the file while deleting some
information or updating some
information.

Cost The database system is expensive to The file system approach is cheaper to
design. design.

Data Redundancy is the concept of In this, the files and application


Redundancy and repetition of data Due to the programs are created by different
Inconsistency centralization of the database, the programmers so that there exists a lot
problems of data redundancy and of duplication of data which may lead
inconsistency are controlled. to inconsistency.

Structure The database structure is complex to The file system approach has a simple
design. structure.

Integrity Integrity Constraints are easy to Integrity Constraints are difficult to


Constraints apply. implement in file system.

SHWETA K/SWAPNA A Page 5


RDBMS UNIT - I III SEM CA
__________________________________________
Data Models In the database approach, there is In the file system approach, there is no
concept of data models exists. concept of data models exists.

Flexibility changes are done more easily with a The flexibility of the system is less as
database approach. compared to the DBMS approach.

Examples Oracle, SQL Server, Sybase etc. Cobol, C++ etc.

Q:5) WHA IS DATA BASE APPROACH? EXPLAIN TYPES OF DATA BASES?


A) Database is an organized collection of data, so that it can be easily accessed and managed.
You can organize data into tables, rows, columns, and index it to make it easier to find relevant
information.

Types of Databases

There are various types of databases used for storing different varieties of data:

1) Centralized Database: It is the type of database that stores data at a centralized database
system. It comforts the users to access the stored data from different locations through several
applications. An example of a Centralized database can be Central Library that carries a central
database of each library in a college/university.

2) Distributed Database

Unlike a centralized database system, in distributed systems, data is distributed among different
database systems of an organization. These database systems are connected via communication links.
Such links help the end-users to access the data easily. We can further divide a distributed database
system into:

SHWETA K/SWAPNA A Page 6


RDBMS UNIT - I III SEM CA
__________________________________________
o Homogeneous DDB: Those database systems which execute on the same operating system
and use the same application process and carry the same hardware devices.
o Heterogeneous DDB: Those database systems which execute on different operating systems
under different application procedures, and carries different hardware devices.

3) Relational Database: This database is based on the relational data model, which stores data in
the form of rows(tuple) and columns(attributes), and together forms a table(relation). A relational
database uses SQL for storing, manipulating, as well as maintaining the data.

4) NoSQL Database : NoSQL databases (Not Only SQL") are non-tabular databases and store data differently
than relational tables.

a. Key-value storage: It is the simplest type of database storage where it stores every single
item as a key (or attribute name) holding its value, together.
b. Document-oriented Database: A type of database used to store data as JSON-like
document. It helps developers in storing data by using the same document-model format as
used in the application code.
c. Graph Databases: It is used for storing vast amounts of data in a graph-like structure. Most
commonly, social networking websites use the graph database.
d. Column-Family: It is similar to the data represented in relational databases. Here, data is
stored in large columns together, instead of storing in rows.

5) Cloud Database: A type of database where data is stored in a virtual environment and executes
over the cloud computing platform. It provides users with various cloud computing services (SaaS,
PaaS, IaaS, etc.) for accessing the database.

6) Object-oriented Databases

SHWETA K/SWAPNA A Page 7


RDBMS UNIT - I III SEM CA
__________________________________________
The type of database that uses the object-based data model approach for storing data in the database
system. The data is represented and stored as objects which are similar to the objects used in the
object-oriented programming language.

7) Hierarchical Databases

It is the type of database that stores data in the form of parent-children relationship nodes. Here, it
organizes data in a tree-like structure. Each child record in the tree will contain only one parent. On
the other hand, each parent record can have multiple child records.

8) Network Databases

It is the database that typically follows the network data model. Here, the representation of data is in
the form of nodes connected via links between them. Unlike the hierarchical database, it allows each
record to have multiple children and parent nodes to form a generalized graph structure.

6) EXPLAIN THREE LEVEL ARCHITECHTURE OF DBMS or LOGICAL


ARCHITECTURE
A) DBMS Three Level Architecture Diagram

SHWETA K/SWAPNA A Page 8


RDBMS UNIT - I III SEM CA
__________________________________________
Schema: A database schema is the skeleton structure that represents the logical view of the entire
database. It defines how the data is organized and how the relations among them are associated. A
database schema defines its entities and the relationship among them.

This architecture has three levels:


1. External level
2. Conceptual level
3. Internal level

1. External level

It is also called view level. An external schema describes the part of the database which specific user
is interested in. It hides the unrelated details of the database from the user. There may be "n" number
of external views for each database.

An external view is just the content of the database as it is seen by some specific particular user. For
example, a user from the sales department will see only sales related data.

2. Conceptual level

It is also called logical level. The conceptual schema describes the Database structure of the whole
database for the community of users. This schema hides information about the physical storage
structures and focuses on describing data types, entities, attributes , and their relationships etc.

This logical level comes between the user level and physical storage view. However, there is only
single conceptual view of a single database.

3. Internal level

The internal schema defines the physical storage structure of the database. The internal
schema is a very low-level representation of the entire database. It contains multiple occurrences of
multiple types of internal record. In the ANSI term, it is also called "stored record'.

SHWETA K/SWAPNA A Page 9


RDBMS UNIT - I III SEM CA
__________________________________________
Q:7) Explain physical DBMS architecture.
A)PHYSICAL DBMS ARCHITECTURE

The physical architecture defines the software components used to process and enter data, and how
these software components are related and interconnected. Though it is not possible to simplify the
component structure of a DBMS, it is possible to recognize a number of key functions which are similar
to most database management systems. The components that normally execute these functions are
shown in Figure, which depicts the physical architecture of a typical DBMS.

Figure: DBMS Structure

Based on many functions, the database system may be partitioned. Some functions (for example, file
systems) may be given by the operating system.

• Data Definition Language(DDL) - Set of commands required to define the format of data.
• Data Manipulation Language(DML) - Set of commands that modify, process data.
• DML Precompiler - It converts DML statements embedded in an application program to normal
procedural calls in the host language. It interacts with the query processor in order to generate
the appropriate code.
• DDL Compiler - It converts DDL statements into a set of tables containing metadata tables –
which are in a form that can be used by other components of the DBMS. These are stored in
system catalog or data dictionary.
• Data Manager - Manages the allocation of space on disk storage.
• Query Processor - Responsible for receiving query language statements and changing to a form
the DBMS can understand. It has two parts : parser and query optimizer.

SHWETA K/SWAPNA A Page 10


RDBMS UNIT - I III SEM CA
__________________________________________
Q8) Who is A DBA (Database Administrator)? Explain role and duties of DBA.

A) A Database Administrator is a person or a group of people who are responsible for managing all
the activities related to database system. This job requires a high level of expertise by a person or
group of people. There are very rare chances that only a single person can manage all the database
system activities so companies always have a group of people who take care of database system.

Role, Duties and Responsibilities of database Administrator (DBA)


1. Installing and Configuration of database: DBA is responsible for installing the database
software. He configures the software of database and then upgrades it if needed. There is many database
software like oracle, Microsoft SQL and MySQL in the industry so DBA decides how the installing and
configuring of this database software will take place.
2. Deciding the hardware device
Depending upon the cost, performance and efficiency of the hardware, it is DBA who have the duty of
deciding which hardware devise will suit the company requirement. It is hardware that is an interface
between end users and database so it needed to be of best quality.
2. Managing Data Integrity
Data integrity should be managed accurately because it protects the data from unauthorized use. DBA
manages relationship between the data to maintain data consistency.
3. Decides Data Recovery and Back up method
If any company is having a big database, then it is likely to happen that database may fail at any instance.
It is requiring that a DBA takes backup of entire database in regular time span. DBA has to decide that
how much data should be backed up and how frequently the back should be taken. Also, the recovery
of data base is done by DBA if they have lost the database.
4. Tuning Database Performance
Database performance plays an important role for any business. If user is not able to fetch data speedily
then it may loss company business. So, by tuning a modifying SQLl commands a DBA can improves the
performance of database.
5. Capacity Issues
All the databases have their limits of storing data in it and the physical memory also has some
limitations. DBA has to decide the limit and capacity of database and all the issues related to it.
6. Database design
The logical design of the database is designed by the DBA. Also, a DBA is responsible for physical design,
external model design, and integrity control.
7. Database accessibility
DBA writes subschema to decide the accessibility of database. He decides the users of the database and
also which data is to be used by which user. No user has to power to access the entire database without
the permission of DBA.
8. Decides validation checks on data
DBA has to decide which data should be used and what kind of data is accurate for the company. So he
always puts validation checks on data to make it more accurate and consistence.
9. Monitoring performance
If database is working properly then it doesn’t mean that there is no task for the DBA. Yes f course, he
has to monitor the performance of the database. A DBA monitors the CPU and memory usage.

SHWETA K/SWAPNA A Page 11


RDBMS UNIT - I III SEM CA
__________________________________________
10. Decides content of the database
A database system has many kinds of content information in it. DBA decides fields, types of fields, and
range of values of the content in the database system. One can say that DBA decides the structure of
database files.
11. Provides help and support to user
If any user needs help at any time then it is the duty of DBA to help him. Complete support is given to
the users who are new to database by the DBA.
12. Database implementation
Database has to be implemented before anyone can start using it. So, DBA implements the database
system. DBA has to supervise the database loading at the time of its implementation.
13. Improve query processing performance
Queries made by the users should be performed speedily. As we have discussed that users need fast
retrieval of answers so DBA improves query processing by improving their performance.So, these were
the Role, Duties and Responsibilities of database Administrator (DBA).

Q9) What is data dictionary?


A) Data Dictionary consists of database metadata. It has records about objects in the database.
Metadata is simply defined as data about data.
Meta data in Relational database:
Relational databases store and provide access not only data but also metadata in a structure called
data dictionary or system catalog. It holds information about:
• tables,
• columns,
• data types,
• table relationship,
• constraints etc.
Data Dictionary consists of
Data Dictionary consists of the following information −
• Name of the tables in the database
• Constraints of a table i.e. keys, relationships, etc.
• Columns of the tables that related to each other
• Owner of the table
• Last accessed information of the object
• Last updated information of the object
An example of Data Dictionary can be personal details of a student −
Example
<StudentPersonalDetails>
Student_ID Student_Name Student_Address Student_City

SHWETA K/SWAPNA A Page 12


RDBMS UNIT - I III SEM CA
__________________________________________
The following is the data dictionary for the above fields −

Q10) What is Data file indices in DBMS ?


A) Indexing is a way to optimize the performance of a database by minimizing the number of disk
accesses required when a query is processed. It is a data structure technique which is used to
quickly locate and access the data in a database.
Indexes are created using a few database columns.
• The first column is the Search key that contains a copy of the primary key or candidate key of
the table. These values are stored in sorted order so that the corresponding data can be accessed
quickly.
Note: The data may or may not be stored in sorted order.
• The second column is the Data Reference or Pointer which contains a set of pointers holding
the address of the disk block where that particular key value can be found.

The indexing has various attributes:


• Access Types: This refers to the type of access such as value based search, range access, etc.
• Access Time: It refers to the time needed to find particular data element or set of elements.
• Insertion Time: It refers to the time taken to find the appropriate space and insert a new data.
• Deletion Time: Time taken to find an item and delete it as well as update the index structure.
• Space Overhead: It refers to the additional space required by the index.

SHWETA K/SWAPNA A Page 13


RDBMS UNIT - I III SEM CA
__________________________________________
Q11) What is data model in DBMS?
A) A Database model defines the logical design and structure of a database and defines how data will
be stored, accessed and updated in a database management system. While the Relational Model is
the most widely used database model, there are other models too:

• Hierarchical Model
• Network Model
• Entity-relationship Model
• Relational Model

Hierarchical Model
In hierarchical model, data is organized into tree-like structure with one one-to-many relationship
between two different types of data, for example, one department can have many courses, many
professors and of-course many students. In this model, a child node will only have a single parent
node.

Network Model
This is an extension of the Hierarchical model. In this model data is organized more like a graph, and
are allowed to have more than one parent node.
In this database model data is more related as more relationships are established in this database
model. Also, as the data is more related, hence accessing the data is also easier and fast. This database
model was used to map many-to-many data relationships.
This was the most widely used database model, before Relational Model was introduced.

Entity-relationship Model
E-R Models are defined to represent the relationships into pictorial form to make it
easier for different users to understand.

SHWETA K/SWAPNA A Page 14


RDBMS UNIT - I III SEM CA
__________________________________________
This model is good to design a database, which can then be turned into tables in relational
model(explained below).
Let's take an example, If we have to design a School Database, then Student will be
an entity with attributes name, age, address etc. As Address is generally complex, it can be
another entity with attributes street name, pincode, city etc, and there will be a relationship
between them.
Relationships can also be of different types. To learn about E-R Diagrams in details, click on the link.

Relational Model
In this model, data is organized in two-dimensional tables and the relationship is maintained by
storing a common field.
This model was introduced by E.F Codd in 1970, and since then it has been the most widely used
database model, infact, we can say the only database model used around the world.
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.
In the coming tutorials we will learn how to design tables, normalize them to reduce data redundancy
and how to use Structured Query language to access data from tables.

SHWETA K/SWAPNA A Page 15


RDBMS UNIT - I III SEM CA
__________________________________________
Relational Data Model

Q12) What is Relational Data Model? Briefly explain about Relational Data
Model.
A) The relational data model was introduced by C. F. Codd in 1970. Currently, it is the most widely
used data model. The relational data model describes the world as “a collection of inter-related
relations (or tables).”

Relation
A relation, also known as a table or file, is a subset of the Cartesian product of a list of domains
characterized by a name. And within a table, each row represents a group of related data values. A row,
or record, is also known as a tuple. The columns in a table is a field and is also referred to as an
attribute. You can also think of it this way: an attribute is used to define the record and a record
contains a set of attributes.
Sno Stname course
001 Abc comp

Table
A database is composed of multiple tables and each table holds the data. Following Figure shows a
database that contains three tables.

Column

A database stores pieces of information or facts in an organized way. Understanding how to use and
get the most out of databases requires us to understand that method of organization.

The principal storage units are called columns or fields or attributes. This is how the basic
components of data into which your content can be broken down. When deciding which fields to
create, you need to think generically about your information, for example, drawing out the common
components of the information that you will store in the database and avoiding the specifics that
distinguish one item from another.

Look at the example of an ID card in Figure 7.2 to see the relationship between fields and their data.

SHWETA K/SWAPNA A Page 16


RDBMS UNIT - I III SEM CA
__________________________________________

Domain

A domain is the original sets of atomic values used to model data. By atomic value, we mean that each
value in the domain is indivisible as far as the relational model is concerned. For example:

• The domain of Marital Status has a set of possibilities: Married, Single, Divorced.
• The domain of Shift has the set of all possible days: {Mon, Tue, Wed…}.
• The domain of Salary is the set of all floating-point numbers greater than 0 and less than
200,000.
• The domain of First Name is the set of character strings that represents names of people.

In summary, a domain is a set of acceptable values that a column is allowed to contain. This is based
on various properties and the data type for the column

Records
Just as the content of any one document or item needs to be broken down into its constituent bits of
data for storage in the fields, the link between them also needs to be available so that they can be
reconstituted into their whole form. Records allow us to do this. Records contain fields that are
related, such as a customer or an employee. As noted earlier, a tuple is another term used for record.

Records and fields form the basis of all databases. A simple table gives us the clearest picture of how
records and fields work together in a database storage project.

Figure. Example of a simple table by A. Watt.

SHWETA K/SWAPNA A Page 17


RDBMS UNIT - I III SEM CA
__________________________________________
Degree
The degree is the number of attributes in a table. In our example in Figure, the degree is 4.

Cardinality
The number of tuples in a relation is known as cardinality. The In our example defined above has
cardinality 4.

Properties of a Table
• A table has a name that is distinct from all other tables in the database.
• There are no duplicate rows; each row is distinct.
• Entries in columns are atomic. The table does not contain repeating groups or multivalued
attributes.
• Entries from columns are from the same domain based on their data type including:
• number (numeric, integer, float, smallint,…)
• character (string)
• date
• logical (true or false)
• Operations combining different data types are disallowed.
• Each attribute has a distinct name.
• The sequence of columns is insignificant.
• The sequence of rows is insignificant.

Q13) What is a Key? Explain types of keys.


A) Keys
o Keys play an important role in the relational database.
o It is used to identify any record or row of data uniquely from the table. It is also used to
establish and identify relationships between tables.

For example: In Student table, ID is used as a key because it is unique for each student. In PERSON
table, passport_number, license_number, SSN are keys since they are unique for each person.

SHWETA K/SWAPNA A Page 18


RDBMS UNIT - I III SEM CA
__________________________________________
Types of key:

1. Primary key
o It is the first key which is used to identify one and only one instance of an entity uniquely. An
entity can contain multiple keys as we saw in PERSON table. The key which is most suitable
from those lists become a primary key.
o In the EMPLOYEE table, ID can be primary key since it is unique for each employee. In the
EMPLOYEE table, we can even select License_Number and Passport_Number as primary key
since they are also unique.
o For each entity, selection of the primary key is based on requirement and developers.

2. Candidate key
o A candidate key is an attribute or set of an attribute which can uniquely identify a tuple.
o The remaining attributes except for primary key are considered as a candidate key. The
candidate keys are as strong as the primary key.

For example: In the EMPLOYEE table, id is best suited for the primary key. Rest of the attributes
like SSN, Passport_Number, and License_Number, etc. are considered as a candidate key.

SHWETA K/SWAPNA A Page 19


RDBMS UNIT - I III SEM CA
__________________________________________

3. Super Key

Super key is a set of an attribute which can uniquely identify a tuple. Super key is a superset of a
candidate key.

For example: In the above EMPLOYEE table, for (EMPLOEE_ID, EMPLOYEE_NAME) the name
of two employees can be the same, but their EMPLYEE_ID can't be the same. Hence, this
combination can also be a key.

The super key would be EMPLOYEE-ID, (EMPLOYEE_ID, EMPLOYEE-NAME), etc.

4. Foreign key
o Foreign keys are the column of the table which is used to point to the primary key of another
table.
o In a company, every employee works in a specific department, and employee and department
are two different entities. So we can't store the information of the department in the employee
table. That's why we link these two tables through the primary key of one table.
o We add the primary key of the DEPARTMENT table, Department_Id as a new attribute in the
EMPLOYEE table.
o Now in the EMPLOYEE table, Department_Id is the foreign key, and both the tables are
related.

SHWETA K/SWAPNA A Page 20


RDBMS UNIT - I III SEM CA
__________________________________________
Types of constraints

Q14) Explain types of Integrity Constraints in DBMS.


A) Integrity Constraints
o Integrity constraints are a set of rules. It is used to maintain the quality of information.
o Integrity constraints ensure that the data insertion, updating, and other processes have to be
performed in such a way that data integrity is not affected.
o Thus, integrity constraint is used to guard against accidental damage to the database.

Types of Integrity Constraint

1. Domain constraints
o Domain constraints can be defined as the definition of a valid set of values for an attribute.
o The data type of domain includes string, character, integer, time, date, currency, etc. The value
of the attribute must be available in the corresponding domain.
Example:

2. Entity integrity constraints


o The entity integrity constraint states that primary key value can't be null.
o This is because the primary key value is used to identify individual rows in relation and if the
primary key has a null value, then we can't identify those rows.
o A table can contain a null value other than the primary key field.

Example:

SHWETA K/SWAPNA A Page 21


RDBMS UNIT - I III SEM CA
__________________________________________

3. Referential Integrity Constraints


o A referential integrity constraint is specified between two tables.
o In the Referential integrity constraints, if a foreign key in Table 1 refers to the Primary Key of
Table 2, then every value of the Foreign Key in Table 1 must be null or be available in Table 2.
Example:

4. Key constraints
o Keys are the entity set that is used to identify an entity within its entity set uniquely.
o An entity set can have multiple keys, but out of which one key will be the primary key. A primary
key can contain a unique and null value in the relational table.

Example:

SHWETA K/SWAPNA A Page 22


RDBMS UNIT - I III SEM CA
__________________________________________
Q 15) Explain Relational Algebra in detail. / List out Relational
Operators
A) Relational algebra is a procedural query language. It gives a step by step process to obtain the
result of the query. It uses operators to perform queries.

Types of Relational operation

1. Select Operation:
o The select operation selects tuples that satisfy a given predicate.
o It is denoted by sigma (σ).
1. Notation: σ p(r)
Where:
σ is used for selection prediction
r is used for relation
p is used as a propositional logic formula which may use connectors like: AND OR and NOT.
These relational can use as relational operators like =, ≠, ≥, <, >, ≤.
For example: LOAN Relation
BRANCH_NAME LOAN_NO AMOUNT

Downtown L-17 1000

Redwood L-23 2000

Perryride L-15 1500

Downtown L-14 1500

Mianus L-13 500

Roundhill L-11 900

Perryride L-16 1300

Input:
1. σ BRANCH_NAME="perryride" (LOAN)

SHWETA K/SWAPNA A Page 23


RDBMS UNIT - I III SEM CA
__________________________________________
Output:
BRANCH_NAME LOAN_NO AMOUNT

Perryride L-15 1500

Perryride L-16 1300

2. Project Operation:
o This operation shows the list of those attributes that we wish to appear in the result. Rest of
the attributes are eliminated from the table.
o It is denoted by ∏.
1. Notation: ∏ A1, A2, An (r)
Where
A1, A2, A3 is used as an attribute name of relation r.
Example: CUSTOMER RELATION
NAME STREET CITY

Jones Main Harrison

Smith North Rye

Hays Main Harrison

Curry North Rye

Johnson Alma Brooklyn

Brooks Senator Brooklyn

Input:
1. ∏ NAME, CITY (CUSTOMER)
Output:
NAME CITY

Jones Harrison

Smith Rye

Hays Harrison

Curry Rye

Johnson Brooklyn

SHWETA K/SWAPNA A Page 24


RDBMS UNIT - I III SEM CA
__________________________________________
Brooks Brooklyn

3. Union Operation:
o Suppose there are two tuples R and S. The union operation contains all the tuples that are
either in R or S or both in R & S.
o It eliminates the duplicate tuples. It is denoted by ∪.
1. Notation: R ∪ S
A union operation must hold the following condition:
o R and S must have the attribute of the same number.
oDuplicate tuples are eliminated automatically.
Example:
DEPOSITOR RELATION
CUSTOMER_NAME ACCOUNT_NO

Johnson A-101

Smith A-121

Mayes A-321

Turner A-176

Johnson A-273

Jones A-472

Lindsay A-284

BORROW RELATION
CUSTOMER_NAME LOAN_NO

Jones L-17

Smith L-23

Hayes L-15

Jackson L-14

Curry L-93

Smith L-11

Williams L-17

Input:
1. ∏ CUSTOMER_NAME (BORROW) ∪ ∏ CUSTOMER_NAME (DEPOSITOR)
SHWETA K/SWAPNA A Page 25
RDBMS UNIT - I III SEM CA
__________________________________________
Output:
CUSTOMER_NAME

Johnson

Smith

Hayes

Turner

Jones

Lindsay

Jackson

Curry

Williams

Mayes

4. Set Intersection:
o Suppose there are two tuples R and S. The set intersection operation contains all tuples
that are in both R & S.
o It is denoted by intersection ∩.
1. Notation: R ∩ S
Example: Using the above DEPOSITOR table and BORROW table
Input:
1. ∏ CUSTOMER_NAME (BORROW) ∩ ∏ CUSTOMER_NAME (DEPOSITOR)
Output:
CUSTOMER_NAME

Smith

Jones

5. Set Difference:
o Suppose there are two tuples R and S. The set intersection operation contains all tuples
that are in R but not in S.
o It is denoted by intersection minus (-).

SHWETA K/SWAPNA A Page 26


RDBMS UNIT - I III SEM CA
__________________________________________
1. Notation: R - S
Example: Using the above DEPOSITOR table and BORROW table
Input:
1. ∏ CUSTOMER_NAME (BORROW) - ∏ CUSTOMER_NAME (DEPOSITOR)
Output:
CUSTOMER_NAME

Jackson

Hayes

Willians

Curry

6. Cartesian product
o The Cartesian product is used to combine each row in one table with each row in the other
table. It is also known as a cross product.
o It is denoted by X.
1. Notation: E X D
Example:
EMPLOYEE
EMP_ID EMP_NAME EMP_DEPT

1 Smith A

2 Harry C

3 John B

DEPARTMENT
DEPT_NO DEPT_NAME

A Marketing

B Sales

C Legal

Input:
1. EMPLOYEE X DEPARTMENT
Output:
SHWETA K/SWAPNA A Page 27
RDBMS UNIT - I III SEM CA
__________________________________________
EMP_ID EMP_NAME EMP_DEPT DEPT_NO DEPT_NAME

1 Smith A A Marketing

1 Smith A B Sales

1 Smith A C Legal

2 Harry C A Marketing

2 Harry C B Sales

2 Harry C C Legal

3 John B A Marketing

3 John B B Sales

3 John B C Legal

7. Rename Operation:
The rename operation is used to rename the output relation. It is denoted by rho (ρ).
Example: We can use the rename operator to rename STUDENT relation to STUDENT1.
1. ρ(STUDENT1, STUDENT)

Q16) What is an Entity Relationship Diagram (ER Diagram)?


A) An ER diagram shows the relationship among entity sets. An entity set is a group of similar entities
and these entities can have attributes. In terms of DBMS, an entity is a table or attribute of a table in
database, so by showing relationship among tables and their attributes, ER diagram shows the complete
logical structure of a database. Let’s have a look at a simple ER diagram to understand this concept.

A simple ER Diagram:
In the following diagram we have two entities Student and College and their relationship. The
relationship between Student and College is many to one as a college can have many students however
a student cannot study in multiple colleges at the same time. Student entity has attributes such as
Stu_Id, Stu_Name & Stu_Addr and College entity has attributes such as Col_ID & Col_Name.

SHWETA K/SWAPNA A Page 28


RDBMS UNIT - I III SEM CA
__________________________________________
Here are the geometric shapes and their meaning in an E-R Diagram. We will discuss these terms in
detail in the next section(Components of a ER Diagram) of this guide so don’t worry too much about
these terms now, just go through them once.

Rectangle: Represents Entity sets.


Ellipses: Attributes
Diamonds: Relationship Set
Lines: They link attributes to Entity Sets and Entity sets to Relationship Set
Double Ellipses: Multivalued Attributes
Dashed Ellipses: Derived Attributes
Double Rectangles: Weak Entity Sets
Double Lines: Total participation of an entity in a relationship set

Components of a ER Diagram

As shown in the above diagram, an ER diagram has three main components:


1. Entity
2. Attribute
3. Relationship

1. Entity
An entity is an object or component of data. An entity is represented as rectangle in an ER diagram.

For example: In the following ER diagram we have two entities Student and College and these two
entities have many to one relationship as many student’s study in a single college. We will read more
about relationships later, for now focus on entities.

SHWETA K/SWAPNA A Page 29


RDBMS UNIT - I III SEM CA
__________________________________________

Weak Entity:
An entity that cannot be uniquely identified by its own attributes and relies on the relationship with
other entity is called weak entity. The weak entity is represented by a double rectangle. For example –
a bank account cannot be uniquely identified without knowing the bank to which the account belongs,
so bank account is a weak entity.

2. Attribute
Q) What is Attribute in ER model? Explain types of Attribute.
An attribute describes the property of an entity. An attribute is represented as Oval in an ER diagram.

There are four types of attributes:


1. Key attribute
2. Composite attribute
3. Multivalued attribute
4. Derived attribute

1. Key attribute:

A key attribute can uniquely identify an entity from an entity set. For example, student roll number
can uniquely identify a student from a set of students. Key attribute is represented by oval same as
other attributes however the text of key attribute is underlined.

SHWETA K/SWAPNA A Page 30


RDBMS UNIT - I III SEM CA
__________________________________________

2. Composite attribute:

An attribute that is a combination of other attributes is known as composite attribute. For example, In
student entity, the student address is a composite attribute as an address is composed of other
attributes such as pin code, state, country.

3. Multivalued attribute:

An attribute that can hold multiple values is known as multivalued attribute. It is represented
with double ovals in an ER Diagram.

For example – A person can have more than one phone numbers so the phone number attribute is
multivalued.
4. Derived attribute:

A derived attribute is one whose value is dynamic and derived from another attribute. It is
represented by dashed oval in an ER Diagram.

For example – Person age is a derived attribute as it changes over time and can be derived from
another attribute (Date of birth).

SHWETA K/SWAPNA A Page 31


RDBMS UNIT - I III SEM CA
__________________________________________
E-R diagram with multivalued and derived attributes:

3. Relationship

Q) What is Relationship in ER model? Explain types of relationship.


A relationship is represented by diamond shape in ER diagram,

It shows the relationship among entities. There are four types of relationships:
1. One to One
2. One to Many
3. Many to One
4. Many to Many

1. 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. For example, a person has only one passport and a passport is given to
one person.

2. One to Many Relationship


When a single instance of an entity is associated with more than one instances of another entity then
it is called one to many relationship. For example – a customer can place many orders but a order
cannot be placed by many customers.

3. Many to One Relationship


When more than one instances of an entity is associated with a single instance of another entity then
it is called many to one relationship. For example – many students can study in a single college but a
student cannot study in many colleges at the same time.

SHWETA K/SWAPNA A Page 32


RDBMS UNIT - I III SEM CA
__________________________________________

4. Many to Many Relationship


When more than one instances of an entity is associated with more than one instances of another
entity then it is called many to many relationship. For example, a can be assigned to many projects
and a project can be assigned to many students.

Q:17) Explain Total Participation of an Entity set


A Total participation of an entity set represents that each entity in entity set must have at least one
relationship in a relationship set. For example: In the below diagram each college must have at-least
one associated Student.

Q 18) Defining Relationship for College Database


Using the concepts defined earlier, we have identified that strong entities in COLLEGE database are
STUDENT, FACULTY, COURSE and DEPARTMENT. This database also has one weak entity called
GUARDIAN. We can specify the following relationships:
• Head-of, is a 1:1 relationship between FACULTY and DEPARTMENT. Participation of the entity
FACULTY is partial since not all the faculty members participate in this relationship, while the
participation from department side is total, since every department has one head.
• Works_in, is a 1:N relationship between DEPARTMENT and FACULTY. Participation from
both side is total.

SHWETA K/SWAPNA A Page 33


RDBMS UNIT - I III SEM CA
__________________________________________
• Opts, is a 1:N relationship between COURSE and STUDENT. Participation from student side is
total because we are assuming that each student enrolled opts for a course. But the participation
from the course side is partial, since there can be courses that no student has opted for.
• Taught_by, is a M: N relationship between FACULTY and COURSE, as a faculty can teach
many courses and a course can be taught by many faculty members.
• Enrolled, is a 1:N relationship between STUDENT and DEPARTMENT as a student is allowed
to enroll for only one department at a time.
• Has, is a 1:N relationship between STUDENT and GUARDIAN as a student can have more than
one local guardian and one local guardian is assumed to be related to one student only. The weak
entity Guardian has total participation in the relation “Has”.
So now, let us make an E-R diagram for the college database in the next section.

E-R DIAGRAM

SHWETA K/SWAPNA A Page 34


RDBMS UNIT - I III SEM CA
__________________________________________
Q19) Illustrate Converting ER Diagrams to Tables with examples.
A) After designing an ER Diagram,
• ER diagram is converted into the tables in relational model.
• This is because relational models can be easily implemented by RDBMS like MySQL , Oracle
etc.

Following rules are used for converting an ER diagram into the tables-

Rule-01: For Strong Entity Set with Only Simple Attributes-

A strong entity set with only simple attributes will require only one table in relational model.
• Attributes of the table will be the attributes of the entity set.
• The primary key of the table will be the key attribute of the entity set.

Example-

Roll_no Name Gender

table : Student ( Roll_no , Name , Sex )

Rule-02: For Strong Entity Set with Composite Attributes-

• A strong entity set with any number of composite attributes will require only one table in relational
model.
• While conversion, simple attributes of the composite attributes are considered and not the
composite attribute itself.

Example-

SHWETA K/SWAPNA A Page 35


RDBMS UNIT - I III SEM CA
__________________________________________

Roll_no First_name Last_name House_no Street City

Schema : Student ( Roll_no , First_name , Last_name , House_no , Street , City )

Rule-03: For Strong Entity Set With Multi Valued Attributes-

A strong entity set with any number of multi valued attributes will require two tables in relational
model.
• One table will contain all the simple attributes with the primary key.
• Other table will contain the primary key and all the multi valued attributes.

Example-

Roll_no City Roll_no Mobile_no

Rule-04: Translating Relationship Set into a Table-


A relationship set will require one table in the relational model.Attributes of the table are-
• Primary key attributes of the participating entity sets
• Its own descriptive attributes if any. Set of non-descriptive attributes will be the primary key.

Example-

SHWETA K/SWAPNA A Page 36


RDBMS UNIT - I III SEM CA
__________________________________________

Emp_no Dept_id since

table: Works in ( Emp_no , Dept_id , since )

NOTE-

If we consider the overall ER diagram, three tables will be required in relational model-
• One table for the entity set “Employee”
• One table for the entity set “Department”
• One table for the relationship set “Works in”

Rule-05: For Binary Relationships With Cardinality Ratios-

The following four cases are possible-

Case-01: Binary relationship with cardinality ratio m:n


Case-02: Binary relationship with cardinality ratio 1:n
Case-03: Binary relationship with cardinality ratio m:1
Case-04: Binary relationship with cardinality ratio 1:1

Case-01: For Binary Relationship With Cardinality Ratio m:n

Here, three tables will be required-


1. A ( a1 , a2 )
2. R ( a1 , b1 )
3. B ( b1 , b2 )

Case-02: For Binary Relationship With Cardinality Ratio 1:n

SHWETA K/SWAPNA A Page 37


RDBMS UNIT - I III SEM CA
__________________________________________

Here, two tables will be required-


1. A ( a1 , a2 )
2. BR ( a1 , b1 , b2 )

NOTE- Here, combined table will be drawn for the entity set B and relationship set R.

Case-03: For Binary Relationship With Cardinality Ratio m:1

Here, two tables will be required-


1. AR ( a1 , a2 , b1 )
2. B ( b1 , b2 )

NOTE- Here, combined table will be drawn for the entity set A and relationship set R.

Case-04: For Binary Relationship With Cardinality Ratio 1:1

Here, two tables will be required. Either combine ‘R’ with ‘A’ or ‘B’

Way-01:
1. AR ( a1 , a2 , b1 )
2. B ( b1 , b2 )

Way-02:
1. A ( a1 , a2 )
2. BR ( a1 , b1 , b2 )

SHWETA K/SWAPNA A Page 38

You might also like