0% found this document useful (0 votes)
53 views68 pages

Dbms Unit II

The document outlines the syllabus for a Database Management System course at Padmavani Arts & Science College for Women, covering key concepts such as database design, normalization, SQL, and PL/SQL. It details various database types including hierarchical, network, object-oriented, and relational databases, along with their advantages and disadvantages. Additionally, it emphasizes the role of a Database Management System (DBMS) in improving data sharing, security, integration, and decision-making.

Uploaded by

jsuganyact
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)
53 views68 pages

Dbms Unit II

The document outlines the syllabus for a Database Management System course at Padmavani Arts & Science College for Women, covering key concepts such as database design, normalization, SQL, and PL/SQL. It details various database types including hierarchical, network, object-oriented, and relational databases, along with their advantages and disadvantages. Additionally, it emphasizes the role of a Database Management System (DBMS) in improving data sharing, security, integration, and decision-making.

Uploaded by

jsuganyact
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/ 68

PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

DATABASE MANAGEMENT SYSTEM

SYALLBUS
UNIT-I

Database Concepts: Database Systems - Data vs Information - Introducing the database -File system -
Problems with file system – Database systems. Data models - Importance - Basic Building Blocks -
Business rules - Evolution of Data models - Degrees of Data Abstraction.

UNIT-II

Design Concepts: Relational database model - logical view of data-keys -Integrity rules - relational set
operators - data dictionary and the system catalog - relationships -data redundancy revisited -indexes -
codd's rules. Entity relationship model - ER diagram.

UNIT-III

Normalization of Database Tables: Database tables and Normalization – The Need for Normalization –
The Normalization Process – Higher level Normal Form. Introduction to SQL: Data Definition
Commands – Data Manipulation Commands – SELECT Queries – Additional Data Definition
Commands – Additional SELECT Query Keywords – Joining Database Tables.

UNIT-IV

Advanced SQL:Relational SET Operators: UNION – UNION ALL – INTERSECT - MINUS.SQL Join
Operators: Cross Join – Natural Join – Join USING Clause – JOIN ON Clause – Outer Join.Sub Queries
and Correlated Queries: WHERE – IN – HAVING – ANY and ALL – FROM. SQL Functions: Date and
Time Function – Numeric Function – String Function – Conversion Function.

UNIT-V

PL/SQL:A Programming Language: History – Fundamentals – Block Structure – Comments – Data


Types – Other Data Types – Variable Declaration – Assignment operation –Arithmetic operators.Control
Structures and Embedded SQL: Control Structures – Nested Blocks – SQL in PL/SQL – Data
Manipulation – Transaction Control statements. PL/SQL Cursors and Exceptions: Cursors – Implicit
Cursors, Explicit Cursors and Attributes – Cursor FOR loops – SELECT…FOR UPDATE – WHERE
CURRENT OF clause – Cursor with Parameters – Cursor Variables – Exceptions – Types of Exceptions.

1|P ag e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

UNIT-I

Database Concepts

1.1DATABASE: INTRODUCTION
 A database is an electronic store of data.
 It is a repository that stores information about different “things” and also contains relationships
among those different “things.”
 Let us examine some of the basic terms used to describe the structure of a database:
 A person, place, event, or item is called an entity.
 The facts describing an entity are known as data.
 For example, if you were a registrar in a college, you would like to have all the information about
the students. Each student is an entity in such a scenario.
 Each entity can be described by its characteristics, which are known as attributes.
 For example, some of the likely attributes for a college student are student identification number,
last name, first name, phone number, Social Security number, gender, birthdate, and so on.
 All the related entities are collected together to form an entity set. An entity set is given a singular
name.
 For example, the STUDENT entity set contains data about students only. All related entities in the
STUDENT entity set are students. Similarly, a company keeps track of all its employees in an
entity set called EMPLOYEE.The EMPLOYEE entity set does not contain information about the
company’s customers, because it wouldn’t make any sense.
 A database is a collection of entity sets. For example, a college’s database may include
information about entities such as student, faculty, course, term, course section, building,
registration information, and so on.
 The entities in a database are likely to interact with other entities. The interactions between the
entity sets are called relationships.
 For example, a student takes a course section (CRSSECTION), so the relationship between
STUDENT and CRSSECTION is takes. A faculty member teaches in a building, so the
relationship between FACULTY and BUILDING is teaches.

1.2 Data versus Information


 To understand what drives database design, you must understand the difference between data and
information.
 Data consists of raw facts. The word raw indicates that the facts have not yet been processed to
reveal their meaning.
 For example, suppose that a university tracks data on faculty members for reporting to accrediting
bodies.
 To get the data for each faculty member into the database, you would provide a screen to allow for
convenient data entry, complete with drop-down lists, combo boxes, option buttons, and other
data-entry validation controls.

2|P ag e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

 Information is the result of processing raw data to reveal its meaning. Data processing can be
as simple as organizing data to reveal patterns or as complex as making forecasts or drawing
inferences using statistical modeling.
 To reveal meaning, information requires context.
 For example, an average temperature reading of 105 degrees does not mean much unless you also
know its context: Is this reading in degrees Fahrenheit or Celsius? Is this a machine temperature, a
body temperature, or an outside air temperature?
 Information can be used as the foundation for decision making.
 For example, the data summary for the faculty can provide accrediting bodies with insights that
are useful in determining whether to renew accreditation for the university. Keep in mind that raw
data must be properly formatted for storage, processing, and presentation.


1.3 INTRODUCING THE DATABASE

DATA MANAGEMENT
 A process that focuses on data collection, storage, and retrieval. Common data management
functions include addition, deletion, modification, and listing.

DATABASE
 A shared, integrated computer structure that houses a collection of related data. A database
contains two types of data: end-user data (raw facts) and metadata.
 Metadata Data about data; that is, data about data characteristics and relationships. See also
data dictionary.

1-5 DATABASE MANAGEMENT SYSTEM (DBMS)

3|P ag e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

 The collection of programs that manages the database structure and controls access to the data
stored in the database.
 Efficient data management typically requires the use of a computer database.
 A database is a shared, integrated computer structure that stores a collection of the following:
 End-user data—that is, raw facts of interest to the end user
 Metadata, or data about data, through which the end-user data is integrated and managed The
metadata describes the data characteristics and the set of relationships that links the data found
within the database.
 For example, the metadata component stores information such as the name of each data element,
the type of values (numeric, dates, or text) stored on each data element, and whether the data
element can be left empty.
 The metadata provides information that complements and expands the value and use of the data.
In short, metadata presents a more complete picture of the data in the database Collection of self-
describing data.
 A database management system (DBMS) is a collection of programs that manages the database
structure and controls access to the data stored in the database.
 A database resembles a very well-organized electronic filing cabinet in which powerful software
(the DBMS) helps manage the cabinet’s contents.

1-A ROLE AND ADVANTAGES OF THE DBMS


 The DBMS serves as the intermediary between the user and the database. The database structure
itself is stored as a collection of files, and the only way to access the data in those files is through
the DBMS.
 Figure 1.3 emphasizes the point that the DBMS presents the end user (or application program)
with a single, integrated view of the data in the database.

4|P ag e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

 The DBMS receives all application requests and translates them into the complex operations
required to fulfill those requests.
 The DBMS hides much of the database’s internal complexity from the application programs and
users.
 The application program might be written by a programmer using a programming language, such
as Visual Basic. NET, Java, or C #or it might be created through a DBMS utility program.

A DBMS PROVIDES THESE ADVANTAGES:

 Improved data sharing.


 The DBMS helps create an environment in which end users have better access to more and better-
managed data. Such access makes it possible for end users to respond quickly to changes in their
environment.
 Improved data security.
 The more users access the data, the greater the risks of data security breaches. Corporations invest
considerable amounts of time, effort, and money to ensure that corporate data is used properly.
 A DBMS provides a framework for better enforcement of data privacy and security policies.
 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.
 It becomes much easier to see how actions in one segment of the company affect other segments.
 Minimized data inconsistency.
 Data inconsistency exists when different versions of the same data appears in different places.
 Improved data access.
 The DBMS makes it possible to produce quick answers to ad hoc queries. From a database
perspective, a query is a specific request issued to the DBMS for data manipulation.
 Improved decision making. Better-managed data and improved data access make it possible to
generate better-quality information, on which better decisions are based.
 The quality of the information generated depends on the quality of the underlying data. Data
quality is a comprehensive approach to promoting the accuracy, validity, and timeliness of the
data. While the DBMS does not guarantee data quality, it provides a framework to facilitate data
quality initiatives.
 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.

TYPES OF DATABASES
 Databases can be classified based on their structure, usage, storage methods, and intended
application. Understanding these types will help us choose the best database for our needs.
 Hierarchical databases
 Network databases
 Object-oriented databases
5|P ag e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

 Relational databases
 Cloud Database
 Centralized Database
 Operational Database
 NoSQL databases
Hierarchical Databases
 Hierarchical databases organize data in a tree-like structure, where each parent record can
have multiple child records.
 This model works well for scenarios where data follows a predefined hierarchical relationship,
where data is arranged in levels or ranks.
 For example, in a university, "University" is at the top level, while "Departments" and
"Administration" are at lower levels, even though they are distinct entities.


Hierarchical Database Example
 This structure can also be viewed as a parent-child relationship, where each parent record can
have multiple child records, but a child record can only have one parent.
 As more data is added, the structure expands like a tree.
 Example: IBM's Information Management System (IMS) is a well-known hierarchical
database.
Advantages
 Simple and fast for straightforward, hierarchical data.
 Efficient data retrieval when the structure is known in advance.
Disadvantages
 Lack of flexibility; changes to the hierarchy structure are difficult to implement.
 Not suitable for complex relationships beyond a parent-child structure.
 Network Databases
 A network databases builds on the hierarchical model but allows child records to link
to multiple parent records, creating a web-like structure of interconnected data.
 This results in a more flexible structure, often referred to as a graph model, where entities can
be connected in many different ways.
 For example, in a university database, "Students," "Faculty," and "Resources" can be linked
to both "Departments" and "Clubs," forming a flexible, two-directional relationship.

6|P ag e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

Network Database Example


 This model is ideal for complex frameworks as it effectively represents many-to-many
relationships. Additionally, its structure simplifies the use of certain database management
languages.
 Example: The Integrated Data Store (IDS) is a well-known example of a network database.
Advantages:
 More flexible than hierarchical models.
 Supports many-to-many relationships effectively.
Disadvantages:
 Complex to design and manage.
 Changes to the database schema can be difficult to implement.
Object-Oriented Databases
 Object-oriented databases are based on the principles of object-oriented programming (OOP),
where data is stored as objects. These objects include attributes (data) and methods (functions),
making them easily referenced and manipulated.
 These databases are designed to handle complex data structures such as multimedia, graphics,
and large files.

Object-Oriented Example
 For instance, a "Person" object in the database could include attributes
like Name and Address and methods like getLatestAddress() to retrieve information.

7|P ag e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

 This approach reduces the workload on the database by allowing objects to be reused and
linked directly, streamlining data access and manipulation.
 Each object behaves as an instance of the database model, enabling efficient operations.
Advantages:
 Supports complex data types and relationships.
 Useful for applications requiring complex data models, such as CAD (Computer-Aided
Design) or multimedia systems.
Disadvantages:
 Requires knowledge of object-oriented programming.
 Generally less widely supported than relational databases.
 A practical example of this model is the Berkeley DB software library, which is designed
for fast and efficient query responses in embedded systems.
 Object-oriented databases are especially useful for applications involving complex data types
or multimedia content.
Relational Databases
 Relational databases are the most widely used type of database today. They store data
in tables, with rows representing records and columns representing attributes of the records.
 In this database, every piece of information has a relationship with every other piece of
information.
 This is on account of every data value in the database having a unique identity in the form of a
record.

Note that all data is tabulated in this model.


 Therefore, every row of data in the database is linked with another row using a primary key.
Similarly, every table is linked with another table using a foreign key. Refer to the diagram
below and notice how the concept of 'Keys' is used to link two tables.



Relational Database Example

8|P ag e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

 Due to this introduction of tables to organize data, it has become exceedingly popular.
 In consequence, they are widely integrated into Web-Ap interfaces to serve as ideal
repositories for user data.
 What makes it further interesting in the ease in mastering it, since the language used to interact
with the database is simple (SQL in this case) and easy to comprehend.
 In Relational databases, scaling and traversing through data is quite a lightweight task in
comparison to Hierarchical Databases. Example: MySQL, PostgreSQL, and Oracle Database
are some popular relational databases.
Advantages:
 Structured and easy to use.
 Widely adopted, making it easier to find support and resources.
 Supports ACID (Atomicity, Consistency, Isolation, Durability) properties to ensure data
integrity.
Disadvantages:
 Can be difficult to scale for very large datasets or high-transaction environments.
 Requires careful schema design.
Cloud Databases
 A cloud database operates in a virtual environment hosted on cloud computing platforms.
 It is designed for storing, managing, and executing data over the internet,
providing flexibility and scalability.
 Cloud databases are widely used for applications requiring dynamic workloads, as they
eliminate the need for on-premises infrastructure.
 Common cloud services for accessing and managing databases include SaaS (Software as a
Service) and PaaS (Platform as a Service), which simplify database operations for businesses.
Popular cloud platforms offering database services include:
 Amazon Web Services (AWS)
 Google Cloud Platform (GCP)
 Microsoft Azure
 ScienceSoft, etc.
Advantages:
 High scalability and flexibility.
 Easier to manage and maintain as most of the infrastructure is managed by cloud service
providers.
 Reduces capital expenditure by offering pay-as-you-go models.
Disadvantages:
 Reliance on internet connectivity.
 Security concerns regarding cloud data storage.
Centralized Databases
 A centralized database is a database stored and managed at a single location, such as
a central server or data center.
 It ensures higher security and consistency as all data is maintained in one place, making it
easier to control and manage.
 Users access the database remotely to fetch or update information. Centralized databases are
commonly used in enterprise systems where data consistency and security are critical.
However, scalability and performance limitations should be carefully considered.
Advantages
 Data Security: Centralized storage makes it easier to implement robust security measures.
 Reduced Redundancy: Data duplication is minimized, ensuring efficiency.
 Consistency: A single data source ensures uniformity across the system.

9|P ag e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

Disadvantages
 Response Time: The large size of centralized databases can lead to slower data retrieval times.
 Difficulty in Modifications: Modifying, deleting, or updating data can be challenging and
time-consuming, especially for large datasets.
Personal Databases
 A personal database is a small-scale database designed for a single user, typically used on
personal computers or mobile devices.
 These databases are ideal for managing individual data like contacts, budgets, notes,
or schedules.
 They are lightweight, easy to use, and require minimal database administration, making them
accessible for non-technical users. Examples are:
 Microsoft Access: A simple database solution for personal or small business needs.
 SQLite: A lightweight, self-contained database commonly used in mobile and desktop
applications.
Advantages:
 Ease of Use: Simple to set up and manage without requiring advanced technical skills.
 Low Storage Requirements: Occupies minimal space, making it suitable for smaller devices.
Disadvantages:
 Limited scalability and features.
 Not suitable for large-scale applications.
Operational Databases
 An operational database is designed to manage and process real-time data for daily
operations within organizations and businesses.
 It allows users to create, update, and delete data efficiently, ensuring that the database reflects
current activities and transactions.
 These databases handle live transactions and provide quick access to up-to-date data.
 Example: SAP HANA is an example of an operational database used for high-speed
transactions and analytics.
Advantages:
 Easy to Fetch: Data retrieval is quick and efficient, supporting operational tasks.
 Structured Data: Organizes data systematically for better management and access.
 Real-Time Processing: Enables immediate updates, ensuring data is always current.
Disadvantages:
 Requires constant maintenance and monitoring to ensure real-time data accuracy.
NoSQL Databases
 A NoSQL database (short for "non-SQL" or "non-relational") provides a mechanism
for storing and retrieving data that does not rely on traditional table-based relational models.
Instead,
 it uses flexible data models like key-value pairs, documents, column families, or graphs,
making it ideal for handling unstructured, semi-structured, and structured data.
 NoSQL databases are known for their simplicity of design, horizontal scalability (adding
more servers for scaling), and high availability.
 Unlike relational databases, their data structures allow faster operations in certain use
cases. MongoDB, for instance, is a widely used document-based NoSQL database.
Advantages
 Easily scales horizontally by adding more servers.
 Can be run on commodity hardware, lowering costs.
 Optimized for large volumes of data and fast queries.
 Handles unstructured, semi-structured, or structured data.

10 | P a g e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

Disadvantages
 NoSQL is an open-source database.
 GUI is not available
 Backup is a weak point for some NoSQL databases like MongoDB.
 Large document size.

1.6 File system


 A filesystem is a method used by operating systems to store and manage files on storage devices.
It provides basic mechanisms for:
 Creating, reading, writing, and deleting files
 Managing file metadata (name, size, permissions, timestamps)
 Structuring directories
 Common filesystems include NTFS, FAT32, ext4, etc.


Problems with File System
 Below are the main problems that led to the development and widespread use of DBMS:
Data Redundancy and Inconsistency
 Redundancy: Same data is stored in multiple files.
 Inconsistency: Changes in one file may not reflect in others, leading to mismatched data.
 🧾 Example: A student's address is stored in both the student.txt and fees.txt files. If the address is
updated in one file but not the other, data becomes inconsistent.
No Data Sharing
 Data is scattered in separate files and used by individual applications.
 Sharing data between different users or programs is difficult and error-prone.
Difficult Data Access
 Data access needs custom programs.
 Simple queries require complex code.
 🧾 Example: To find all students from "New York", you need to manually open the file, read each
line, and apply logic to filter the result.
Lack of Security
 File systems provide only basic protection (e.g., read/write permissions).
 No fine-grained access control (e.g., restrict certain users from accessing specific parts of the
data).
No Concurrency Control
 Multiple users accessing the same file can cause conflicts or data corruption.
 No built-in mechanism to handle concurrent updates.
Data Integrity Problems
 No automatic checks for valid data.
 You must manually code rules like "Age must be > 0".
11 | P a g e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

Difficult Backup and Recovery


 No built-in backup and recovery mechanisms.
 Must manually handle saving and restoring data.
Poor Scalability
 As data volume grows, managing, searching, and updating flat files becomes slow and inefficient.
 Tight Coupling Between Data and Application
 Application logic and data format are hard-coded.
 Any change in data structure requires reworking the application code.

How DBMS Solves These Problems


 Problem in File System  Solution in DBMS
 Redundancy  Normalization & central database
 Inconsistency  Referential integrity & constraints
 No sharing  Multi-user access
 Difficult access  SQL for easy querying
 No security  User roles and permissions
 No concurrency control  Transactions & locking
 No backup/recovery  Logging and recovery tools
 Poor scalability  Indexing & optimized storage
 Tight coupling  Data abstraction & independence
DATABASE SYSTEMS

 The term database system refers to an organization of components that define and regulate the
collection, storage, management, and use of data within a database environment.
 From a general management point of view, the database system is composed of the five major
parts shown in Figure 1.10:
12 | P a g e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

Hardware.
 Hardware refers to all of the system’s physical devices, including computers (PCs, tablets,
workstations, servers, and supercomputers), storage devices, printers, network devices (hubs,
switches, routers, fiber optics), and other devices (automated teller machines, ID readers, and so
on).
Software.
 Although the most readily identified software is the DBMS itself, three types of software are
needed to make the database system function fully:
Operating system
 Software, DBMS software, and application programs and utilities.
 Operating system software manages all hardware components and makes it possible for all other
software to run on the computers. Examples of operating system software include Microsoft
Windows, Linux, Mac OS, UNIX, and MVS.

 DBMS software manages the database within the database system. Some examples of DBMS
software include Microsoft’s SQL Server, Oracle Corporation’s Oracle, Oracle’s MySQL, and
IBM’s DB
 Application programs and utility software are used to access and manipulate data in the DBMS
and to manage the computer environment in which data access and manipulation take place
 Application programs are most commonly used to access data within the database to generate
reports, tabulations, and other information to facilitate decision making. Utilities are the software
tools used to help manage the database system’s computer components.
 For example, all of the major DBMS vendors now provide graphical user interfaces (GUIs) to
help create database structures, control database access, and monitor database operations.
 People. This component includes all users of the database system. On the basis of primary job
functions, five types of users can be identified in a database system: system administrators,

13 | P a g e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

database administrators, database designers, system analysts and programmers, and end users.
Each user type, described next, performs both unique and complementary functions.
 System administrators oversee the database system’s general operations. – Database
administrators, also known as DBAs, manage the DBMS and ensure that the database is
functioning properly.
 Database Administration and Security. – Database designers design the database structure.
They are, in effect, the database architects.
 If the database design is poor, even the best application programmers and the most dedicated
DBAs cannot produce a useful database environment.
 Because organizations strive to optimize their data resources, the database designer’s job
description has expanded to cover new dimensions and growing.
 System analysts and programmers design and implement the application programs.
 They design and create the data-entry screens, reports, and procedures through which end users
access and manipulate the database’s data. End users are the people who use the application
programs to run the organization’s daily operations.
 For example, sales clerks, supervisors, managers, and directors are all classified as end users.
 High-level end users employ the information obtained from the database to make tactical and
strategic business decisions. •
 Procedures. Procedures are the instructions and rules that govern the design and use of the
database system.
 Procedures are a critical, although occasionally forgotten, component of the system.
 Procedures play an important role in a company because they enforce the standards by which
business is conducted within the organization and with customers.
 Procedures also help to ensure that companies have an organized way to monitor and audit the
data that enter the database and the information generated from those data
 Data. The word data covers the collection of facts stored in the database. Because data is the raw
material from which information is generated, determining which data to enter into the database
and how to organize that data is a vital part of the database designer’s job.
1.7 DATA MODELS

14 | P a g e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)


 A Data Model in Database Management System (DBMS) is the concept of tools that are
developed to summarize the description of the database.
 Data Models provide us with a transparent picture of data which helps us in creating an actual
database. It shows us from the design of the data to its proper implementation of data.
 Types of Relational Models
 Conceptual Data Model
 Representational Data Model
 Physical Data Model
 It is basically classified into 3 types:-
o Conceptual Data Model
 The conceptual data model describes the database at a very high level and is useful to
understand the needs or requirements of the database.
 It is this model, that is used in the requirement-gathering process i.e. before the Database
Designers start making a particular database.
 One such popular model is the entity/relationship model (ER model). The E/R model
specializes in entities, relationships, and even attributes that are used by database designers.
 In terms of this concept, a discussion can be made even with non-computer science(non-
technical) users and stakeholders, and their requirements can be understood.
 Entity-Relationship Model( ER Model):
 It is a high-level data model which is used to define the data and the relationships between
them.
 It is basically a conceptual design of any database which is easy to design the view of data.
 Components of ER Model:
 Entity: An entity is referred to as a real-world object. It can be a name, place, object, class,
etc. These are represented by a rectangle in an ER Diagram.

15 | P a g e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

 Attributes: An attribute can be defined as the description of the entity. These are represented
by Ellipse in an ER Diagram. It can be Age, Roll Number, or Marks for a Student.
 Relationship: Relationships are used to define relations among different entities. Diamonds
and Rhombus are used to show Relationships.
 Characteristics of a conceptual data model
 Offers Organization-wide coverage of the business concepts.
 This type of Data Models are designed and developed for a business audience.
 The conceptual model is developed independently of hardware specifications like data storage
capacity, location or software specifications like DBMS vendor and technology. The focus is to
represent data as a user will see it in the “real world.”
 Conceptual data models known as Domain models create a common vocabulary for all
stakeholders by establishing basic concepts and scope
o Representational Data Model
 This type of data model is used to represent only the logical part of the database and does not
represent the physical structure of the database.
 The representational data model allows us to focus primarily, on the design part of the
database.
 A popular representational model is a Relational model. The relational Model consists
of Relational Algebra and Relational Calculus.
 In the Relational Model, we basically use tables to represent our data and the relationships
between them. It is a theoretical concept whose practical implementation is done in Physical
Data Model.
 The advantage of using a Representational data model is to provide a foundation to form the
base for the Physical model.
 Characteristics of Representational Data Model
 Represents the logical structure of the database.
 Relational models like Relational Algebra and Relational Calculus are commonly used.
 Uses tables to represent data and relationships.
 Provides a foundation for building the physical data model.
Physical Data Model
 The physical Data Model is used to practically implement Relational Data Model. Ultimately,
all data in a database is stored physically on a secondary storage device such as discs and tapes.
 This is stored in the form of files, records, and certain other data structures. It has all the
information on the format in which the files are present and the structure of the databases, the
presence of external data structures, and their relation to each other. Here, we basically save
tables in memory so they can be accessed efficiently.
 In order to come up with a good physical model, we have to work on the relational model in a
better way.
 Structured Query Language (SQL) is used to practically implement Relational Algebra.
 This Data Model describes HOW the system will be implemented using a specific DBMS
system. This model is typically created by DBA and developers. The purpose is actual
implementation of the database.
 Characteristics of a physical data model:
 The physical data model describes data need for a single project or application though it may
be integrated with other physical data models based on project scope.
 Data Model contains relationships between tables that which addresses cardinality and
nullability of the relationships.
 Developed for a specific version of a DBMS, location, data storage or technology to be used in
the project.

16 | P a g e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

 Columns should have exact datatypes, lengths assigned and default values.
 Primary and Foreign keys, views, indexes, access profiles, and authorizations, etc. are defined
 Some Other Data Models
Hierarchical Model
 The hierarchical Model is one of the oldest models in the data model which was developed by
IBM, in the 1950s.
 In a hierarchical model, data are viewed as a collection of tables, or we can say segments that
form a hierarchical relation.
 In this, the data is organized into a tree-like structure where each record consists of one parent
record and many children. Even if the segments are connected as a chain-like structure by
logical associations, then the instant structure can be a fan structure with multiple branches.
 We call the illogical associations as directional associations.
Network Model
 The Network Model was formalized by the Database Task group in the 1960s. This model is
the generalization of the hierarchical model.
 this model can consist of multiple parent segments and these segments are grouped as levels
but there exists a logical association between the segments belonging to any level. Mostly,
there exists a many-to-many logical association between any of the two segments.
Object-Oriented Data Model
 In the Object-Oriented Data Model, data and their relationships are contained in a single
structure which is referred to as an object in this data model.
 In this, real-world problems are represented as objects with different attributes.
 All objects have multiple relationships between them. Basically, it is a combination of Object
Oriented programming and a Relational Database Model.
Float Data Model
 The float data model basically consists of a two-dimensional array of data models that do not
contain any duplicate elements in the array.
 This data model has one drawback it cannot store a large amount of data that is the tables can
not be of large size.
o Context Data Model
 The Context data model is simply a data model which consists of more than one data model.
For example, the Context data model consists of ER Model, Object-Oriented Data Model, etc.
 This model allows users to do more than one thing which each individual data model can do.
Semi-Structured Data Model
 Semi-Structured data models deal with the data in a flexible way. Some entities may have extra
attributes and some entities may have some missing attributes. Basically, you can represent
data here in a flexible way.
Advantages of Data Models
 Data Models help us in representing data accurately.
 It helps us in finding the missing data and also in minimizing Data Redundancy.
 Data Model provides data security in a better way.
 The data model should be detailed enough to be used for building the physical database.
 The information in the data model can be used for defining the relationship between tables,
primary and foreign keys, and stored procedures.
Disadvantages of Data Models
 In the case of a vast database, sometimes it becomes difficult to understand the data model.
 You must have the proper knowledge of SQL to use physical models.
 Even smaller change made in structure require modification in the entire application.
 There is no set data manipulation language in DBMS.

17 | P a g e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

 To develop Data model one should know physical data stored characteristics.
1.7.1 Importance data models

 Data models can facilitate interaction among the designer, the applications programmer, and the
end user.
 A well-developed data model can even foster improved understanding of the organization for
which the database design is developed. In short, data models are a communication tool.
 This important aspect of data modeling was summed up neatly by a client whose reaction was as
follows: “I created this business, I worked with this business for years, and this is the first time
I’ve really understood how all the pieces really fit together.” The importance of data modeling
cannot be overstated.
 Data constitutes the most basic information employed by a system.
 Applications are created to manage data and to help transform data into information, but data is
viewed in different ways by different people.
 For example, contrast the view of a company manager with that of a company clerk. Although
both work for the same company, the manager is more likely to have an enterprise-wide view of
company data than the clerk.
 Even different managers view data differently. For example, a company president is likely to take
a universal view of the data because he or she must be able to tie the company’s divisions to a
common (database) vision.
 A purchasing manager in the same company is likely to have a more restricted view of the data, as
is the company’s inventory manager. In effect, each department manager works with a subset of
the company’s data.
 The inventory manager is more concerned about inventory levels, while the purchasing manager
is more concerned about the cost of items and about relationships with the suppliers of those
items.
 Applications programmers have yet another view of data, being more concerned with data
location, formatting, and specific reporting requirements. Basically, applications programmers
translate company policies and procedures from a variety of sources into appropriate interfaces,
reports, and query screens.

1.8 Data Model Basic Building Blocks


 The basic building blocks of all data models are entities, attributes, relationships, and constraints.
 An entity is a person, place, thing, or event about which data will be collected and stored.
 An entity represents a particular type of object in the real world, which means an entity is
“distinguishable”that is, each entity occurrence is unique and distinct.
 An attribute is a characteristic of an entity. For example, a CUSTOMER entity would be
described by attributes such as customer last name, customer first name, customer phone number,
customer address, and customer credit limit.
 A relationship describes an association among entities. For example, a relationship exists
between customers and agents that can be described as follows: an agent can serve many
customers, and each customer may be served by one agent.
 Data models use three types of relationships:
18 | P a g e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

 ONE-TO-MANY,
 MANY-TO-MANY,
 ONE-TO-ONE.
 The following examples illustrate the distinctions among the three relationships. •

ONE-TO-MANY (1:M OR 1..*) RELATIONSHIP.

 A painter creates many different paintings, but each is painted by only one painter. Thus, the
painter (the “one”) is related to the paintings (the “many”).
 Therefore, database designers label the relationship “PAINTER paints PAINTING” as 1:M.
 Note that entity names are often capitalized as a convention, so they are easily identified.
 Similarly, a customer (the “one”) may generate many invoices, but each invoice (the “many”) is
generated by only a single customer.
 The “CUSTOMER generates INVOICE” relationship would also be labeled 1:M. •

MANY-TO-MANY (M:N OR *..*) RELATIONSHIP.

 An employee may learn many job skills, and each job skill may be learned by many employees.
 Database designers label the relationship “EMPLOYEE learns SKILL” as M:N. Similarly,
 a student can take many classes and each class can be taken by many students, thus yielding the
M:N label for

ONE-TO-ONE (1:1 OR 1..1) RELATIONSHIP.

 A retail company’s management structure may require that each of its stores be managed by a
single employee. In turn, each store manager, who is an employee, manages only a single store.

1.9 Business Rules


 When database designers go about selecting or determining the entities, attributes, and
relationships that will be used to build a data model, they might start by gaining a thorough
understanding of what types of data exist in an organization, how the data is used, and in what
time frames it is used.
 But such data and information do not, by themselves, yield the required understanding of the total
business. From a database point of view, the collection of data becomes meaningful only when it
reflects properly defined business rules.
 A business rule is a brief, precise, and unambiguous description of a policy, procedure, or
principle within a specific organization.
 In a sense, business rules are misnamed: they apply to any organization, large or small—a
business, a government unit, a religious group, or a research laboratory—that stores and uses data
to generate information.
 Business rules derived from a detailed description of an organization’s operations help to create
and enforce actions within that organization’s environment. Business rules must be rendered in
writing and updated to reflect any change in the organization’s operational environment.
 Properly written business rules are used to define entities, attributes, relationships, and constraints.

19 | P a g e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

 Any time you see relationship statements such as “an agent can serve many customers, and each
customer can be served by only one agent,” business rules are at work.
 To be effective, business rules must be easy to understand and widely disseminated to ensure that
every person in the organization shares a common interpretation of the rules.
 Business rules describe, in simple language, the main and distinguishing characteristics of the data
as viewed by the company.

1.10 EVOLUTION OF DATA MODELS.


 In the evolution of data models, some common characteristics have made them
Widely accepted:
 A data model must show some degree of conceptual simplicity without compromising The
semantic completeness of the database. It does not make sense to have A data model that is more
difficult to conceptualize than the real world.
 At the same Time, the model should show clarity and relevance; that is, the data model shouldBe
unambiguous and applicable to the problem domain. A data model must represent The real world
as closely as possible.

20 | P a g e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

1.11DEGREES OF DATA ABSTRACTION.


 That is, a database designer starts with an abstract view of the overall data environment and adds
details as the design comes closer to implementation.
 Using levels of abstraction can also be very helpful in integrating multiple (and sometimes
conflicting) views of data at different levels of an organization.
 In the early 1970s, the American National Standards Institute (ANSI) Standards
 Planning and Requirements Committee (SPARC) defined a framework for data
modeling based on degrees of data abstraction.
 The resulting ANSI/SPARC architecture defines three levels of data abstraction:
EXTERNAL, CONCEPTUAL, AND INTERNAL.
 You can use this framework to better understand database models, as shown in Figure 2.7. In the
figure, the ANSI/SPARC framework has been expanded with the addition of a physical model to
explicitly address physical-level implementation details of the internal model.

21 | P a g e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

The External Model


 The external model is the end users’ view of the data environment.
 The term end users refers to people who use the application programs to manipulate the data and
generate information.
 End users usually operate in an environment in which an application has a specific business unit
focus.
 Companies are generally divided into several business units,such as sales, finance, and marketing.
 Each business unit is subject to specific constraints and requirements, and each one uses a subset
of the overall data in the organization.
 Therefore, end users within those business units view their data subsets as separate from or
external to other units within the organization.
 Because data is being modeled, ER diagrams will be used to represent the external
 views. A specific representation of an external view is known as an external schema.
 Figure 2.8 presents the external schemas for two Tiny College business units: student
 registration and class scheduling. Each external schema includes the appropriate entities,
relationships, processes, and constraints imposed by the business unit.
 Also note that For example, the registration and scheduling external schemas share the entities
CLASS and COURSE.
 The use of external views that represent subsets of the database has some important
Advantages:
 It is easy to identify specific data required to support each business unit’s operations.
 It makes the designer’s job easy by providing feedback about the model’s adequacy.
 Specifically, the model can be checked to ensure that it supports all processes as defined by their
external models, as well as all operational requirements and constraints.
 It helps to ensure security constraints in the database design. Damaging an entire database is more
difficult when each business unit works with only a subset of data.
The Conceptual Model
22 | P a g e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

 The conceptual model represents a global view of the entire database by the entire organization.
 That is, the conceptual model integrates all external views (entities, relationships,
 Constraints, and processes) into a single global view of the data in the enterprise, as shown in
Figure 2.9. Also known as a conceptual schema, it is the basis for the identification and high-level
description of the main data objects (avoiding any database model-specific details).
 The most widely used conceptual model is the ER model. Remember that the ER
 model is illustrated with the help of the ERD, which is effectively the basic database blueprint.
 The ERD is used to graphically represent the conceptual schema.
 The conceptual model yields some important advantages. First, it provides a bird’seye
 (macro level) view of the data environment that is relatively easy to understand. For
 example, you can get a summary of Tiny College’s data environment by examining the
 conceptual model in Figure 2.9.

The Internal Model

 Once a specific DBMS has been selected, the internal model maps the conceptual model to the
DBMS.
 The internal model is the representation of the database as “seen” by the DBMS. In other words,
the internal model requires the designer to match the conceptual model’s characteristics and
constraints to those of the selected implementation model.
 An internal schema depicts a specific representation of an internal model, using the
 database constructs supported by the chosen database.
 The internal schema should map the conceptual model to the relational model constructs. In
particular, the entities in the conceptual model are mapped to tables in the relational model.
Likewise, because a relational database has been selected, the internal schema is expressed using
SQL, the standard language for relational databases.
23 | P a g e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

 In the case of the conceptual model for Tiny College depicted in Figure 2.9, the internal model
was implemented by creating the tables PROFESSOR, COURSE, CLASS, STUDENT,
ENROLL, and ROOM. A simplified version of the internal model for Tiny College is shown in
Figure 2.10.

The Physical Model


 The physical model operates at the lowest level of abstraction, describing the way data is saved on
storage media such as magnetic, solid state, or optical media.
 The physical model requires the definition of both the physical storage devices and the (physical)
access methods required to reach the data within those storage devices, making it both software
and hardware dependent. The storage structures used are dependent on the software (the DBMS
and the operating system) and on the type of storage devices the computer can handle.
 The precision required in the physical model’s definition demands that database designers have a
detailed knowledge of the hardware and software used to implement the database design.
 Early data models forced the database designer to take the details of the physical
 Model’s data storage requirements into account.
 However, the now dominant relational model is aimed largely at the logical level rather than the
physical level; therefore, it does not require the physical-level details common to its predecessors.
 Although the relational model does not require the designer to be concerned about the
 Data’s physical storage characteristics, the implementation of a relational model may require
physical-level fine-tuning for increased performance.
 Fine-tuning is especially important when very large databases are installed in a mainframe
environment, yet even such performance fine-tuning at the physical level does not require
knowledge of physical data storage characteristics.
 The levels of data abstraction are summarized in Table 2.4.

24 | P a g e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

****************UNIT-I COMPLETED****************

25 | P a g e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

UNIT-II
o DESIGN CONCEPTS:

The Relational Database Model

2.1 A Logical View of Data


 The relational model enables you to view data logically rather than physically.
 The practical significance of taking the logical view is that it serves as a reminder of
the simple file concept of data storage. Although the use of a table, quite unlike that of
a file, has the advantages of structural and data independence, a table does resemble a
file from a conceptual point of view.
 Because you can think of related records as being stored in independent tables, the relational
database model is much easier to understand than the hierarchical and network models. Logical
simplicity tends to yield simple and effective database design methodologies.
 Because the table plays such a prominent role in the relational model, it deserves a closer look.
2.2 Tables and Their Characteristics
 A table is perceived as a two-dimensional structure composed of rows and columns.

26 | P a g e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

Using the STUDENT table shown in Figure 3.1


 The STUDENT table is perceived to be a two-dimensional structure composed of
 8 rows (tuples) and 12 columns (attributes).
 Each row in the STUDENT table describes a single entity occurrence within the
 entity set. (The entity set is represented by the STUDENT table.) For example, row
 4 in Figure 3.1 describes a student named Walter H. Oblonski. Given the table contents,
 the STUDENT entity set includes eight distinct entities (rows), or students.
 Each column represents an attribute, and each column has a distinct name.
 All of the values in a column match the attribute’s characteristics. For example,
 the grade point average (STU_GPA) column contains only STU_GPA entries for
 each of the table rows. Data must be classified according to its format and function.
 Although various DBMSs can support different data types, most support at
 least the following:
o Numeric. You can use numeric data to perform meaningful arithmetic procedures.
 For example, in Figure 3.1, STU_HRS and STU_GPA are numeric attributes.
o Character. Character data, also known as text data or string data, can contain any
 character or symbol not intended for mathematical manipulation. In Figure 3.1,
 STU_CLASS and STU_PHONE are examples of character attributes.
o Date. Date attributes contain calendar dates stored in a special format known as
 the Julian date format. In Figure 3.1, STU_DOB is a date attribute.
o Logical. Logical data can only have true or false (yes or no) values. In Figure 3.1,
 the STU_TRANSFER attribute uses a logical data format.
 The column’s range of permissible values is known as its domain. Because the
 STU_GPA values are limited to the range 0–4, inclusive, the domain is [0,4].
 The order of rows and columns is immaterial to the user.
 Each table must have a primary key. In general terms, the primary key (PK) is
 an attribute or combination of attributes that uniquely identifies any given row.
27 | P a g e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

 In this case, STU_NUM (the student number) is the primary key.


2.3 Keys
 A key consists of one or more attributes that determine other attributes. For example, an invoice
number identifies all of the invoice attributes, such as the invoice date and the customer name.
 2.3.1 Types of Keys
 Several different types of keys are used in the relational model, and you need to be familiar with
them.
A composite key is a key that is composed of more than one attribute. An attribute
 that is a part of a key is called a key attribute.
 For example,
 STU_NUM → STU_GPA
 (STU_LNAME, STU_FNAME, STU_INIT, STU_PHONE) → STU_HRS
A superkey is a key that can uniquely identify any row in the table. In other words,
 a superkey functionally determines every attribute in the row.
 In the STUDENT table, STU_NUM is a superkey, as are the composite keys (STU_NUM,
STU_LNAME), (STU_ NUM, STU_LNAME, STU_INIT), and (STU_LNAME, STU_FNAME,
STU_INIT,STU_PHONE).
 In fact, because STU_NUM alone is a superkey, any composite key that has STU_NUM as a key
attribute will also be a superkey. Be careful, however, because not all keys are superkeys.
A foreign key (FK) is the primary key of one table that has been placed into another table to create a
common attribute. In Figure 3.2, the primary key of VENDOR, VEND_CODE, was placed in the
PRODUCT table; therefore, VEND_CODE is a foreign key in PRODUCT.
 One advantage of using a proper naming convention for table attributes is that you can identify
foreign keys more easily.
 For example, because the STUDENT table in Figure 3.1 used a proper naming
 convention, you can identify two foreign keys in the table (DEPT_CODE and PROF_
 NUM) that imply the existence of two other tables in the database (DEPARTMENT and
PROFESSOR) related to STUDENT.
FIGURE 3.2 AN EXAMPLE OF A SIMPLE

REFERENTIAL INTEGRITY
28 | P a g e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

 A condition by which a dependent table’s foreign key must have either a null entry or a
 matching entry in the related table.
SECONDARY KEY
 A key used strictly for data retrieval purposes. For example, customers are not likely to know
 their customer number (primary key), but the combination of last name, first name, middle
 initial, and telephone number will probably match the appropriate table row.

2.4 Dependencies
 The role of a key is based on the concept of determination. Determination is the state in which
knowing the value of one attribute makes it possible to determine the value of another.
 A specific terminology and notation is used to describe relationships based on determination.The
relationship is called functional dependence, which means that the value of one or more attributes
determines the value of one or more other attributes.
 The standard notation for representing the relationship between STU_NUM and STU_LNAME is
as follows:
 STU_NUM → STU_LNAME
 In this functional dependency, the attribute whose value determines another is called the
determinant or the key. The attribute whose value is determined by the other attribute is called the
dependent.
 full functional dependence A condition in which an attribute is functionally dependent on a
composite key but not on any subset of the key.
 composite key A multiple-attribute key.
 key attributes The attributes that form a primary key.
 superkey An attribute or attributes that uniquely identify.
2.5 Integrity Rules
 Relational database integrity rules are very important to good database design. RDBMSs enforce
integrity rules automatically, but it is much safer to make sure your application design conforms
to the entity and referential integrity rules .
 Those rules are summarized in Table 3.4.

29 | P a g e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

30 | P a g e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

Note the following features of Figure 3.3.


Entity integrity.
The CUSTOMER table’s primary key is CUS_CODE. The CUSTOMER primary key column has no null
entries, and all entries are unique. Similarly,the AGENT table’s primary key is AGENT_CODE, and this
primary key column is also free of null entries.
Referential integrity. The CUSTOMER table contains a foreign key, AGENT_CODE,that links entries
in the CUSTOMER table to the AGENT table. The CUS_CODE row identified by the (primary key)
number 10013 contains a null entry in its AGENT_CODE foreign key because Paul F. Olowski does not
yet have a sales representativeassigned to him. The remaining AGENT_CODE entries in the
CUSTOMER table all match the AGENT_CODE entries in the AGENT table.

2.6 RELATIONAL SET OPERATORS

RELATIONAL ALGEBRA
 A set of mathematical principles that form the basis for manipulating relational table contents; the
eight main functions are SELECT, PROJECT, JOIN, INTERSECT, UNION, DIFFERENCE,
PRODUCT, and DIVIDE.
Relational Set Operators
 The relational operators have the property of closure; that is, the use of relational algebra
operators on existing relations (tables) produces new relations. Numerous operators have been
defined. Some operators are fundamental, while others are convenient but can be derived using
the fundamental operators.
Select (Restrict)
 SELECT, also known as RESTRICT, is referred to as a unary operator because it only uses one
table as input. It yields values for all rows found in the table that satisfy a given condition.
 SELECT can be used to list all of the rows, or it can yield only rows that match a specified
criterion. In other words, SELECT yields a horizontal subset of a table.
 SELECT will not limit the attributes returned so all attributes of the table will be included in the
result. The effect of a SELECT operation is shown in Figure 3.4.
 SELECT is denoted by the lowercase Greek letter sigma (σ).
 σcus_code = 10010 (customer)

FIGURE 3.4 SELECT

Originaltabl Newtable
e

SELECT ALLyields

SELECTonlyPRICElessthan$2.00yields

SELECTonlyP_CODE=311452yields

31 | P a g e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

Project
 PROJECT yields all values for selected attributes. It is also a unary operator, PROJECT will
return only the attributes requested, in the order in which they are requested. In other words,
PROJECT yields a vertical subset of a table.
 PROJECT will not limit the rows returned so all rows of the specified attributes will be included
in the result.
 The effect of a PROJECT operation is shown in Figure 3.5. Formally, PROJECT is denoted by
the Greek letter pi (π).
 For example, to PROJECT the CUS_FNAME and CUS_LNAME attributes in the CUSTOMER
table, you would write the following:
 πcus_fname, cus_lname (customer)
FIGURE 3.5 PROJECT
Originaltabl Newtabl
e e
PROJECT PRICE
yields

PROJECT P_DESCRIPT and PRICE


yields

PROJECT P_CODE and PRICE


yields

Union
 UNION combines all rows from two tables, excluding duplicate rows.
 To be used in the UNION, the tables must have the same attribute characteristics; in other words,
the columns and domains must be compatible.
 When two or more tables share the same number of columns,and when their corresponding
columns share the same or compatible domains, they are said to be union-compatible. The effect
of a UNION operation is shown in Figure 3.6.]
 UNION is denoted by the symbol ∪. If the relations SUPPLIER and VENDOR are union
compatible, then a UNION between them would be denoted as follows:
 supplier ∪ vendor
 It is rather unusual to find two relations that are union-compatible in a database.
 Typically, PROJECT operators are applied to relations to produce results that are union-
compatible. For example, assume the SUPPLIER and VENDOR tables are not union-compatible.
If you wish to produce a listing of all vendor and supplier names, then you can PROJECT the
names from each table and then perform a UNION with them.

32 | P a g e
PADMAVANI ARTS & SCIENCE COLLEGE
FIGURE3.6UNION FOR WOMEN (AUTONOMOUS)
UNION yields

 πsupplier_name (supplier) ∪ πvendor_name (vendor)

Intersect
 INTERSECT yields only the rows that appear in both tables. As with UNION,
 the tables must be union-compatible to yield valid results. For example, you cannot use
 INTERSECT if one of the attributes is numeric and one is character-based.
 For the rows to be considered the same in both tables and appear in the result of the INTERSECT,
the entire rows must be exact duplicates. The effect of an INTERSECT operation is shown in
Figure 3.7.
 INTERSECT is denoted by the symbol ∩. If the relations SUPPLIER and VENDOR are union-
compatible, then an INTERSECT between them would be denoted as follows:
• supplier ∩ vendor
 Just as with the UNION operator, it is unusual to find two relations that are union compatible in a
database, so PROJECT operators are applied to relations to produce
 results that can be manipulated with an INTERSECT operator.
 πsupplier_name (supplier) ∩ πvendor_name (vendor)

FIGURE 3.7 INTERSECT

INTERSECT yields

Difference
 DIFFERENCE yields all rows in one table that are not found in theother table; that is, it subtracts
one table from the other. As with UNION, the tables must be union-compatible to yield valid
results.
 The effect of a DIFFERENCE operation is shown in Figure 3.8. However, note that subtracting
the first table from the second table is not the same as subtracting the second table from the first
table.
 DIFFERENCE is denoted by the minus symbol −. If the relations SUPPLIER and VENDOR are
union-compatible, then an DIFFERENCE of SUPPLIER minus VENDOR would be written as
follows:
• supplier − vendor
 Assuming the SUPPLIER and VENDOR tables are not union-compatible, producing a list of any
supplier names that do not appear as vendor names, then you can use a DIFFERENCE operator.
33 | P a g e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

 πsupplier_name (supplier) − πvendor_name (vendor)


FIGURE 3.8 DIFFERENCE
DIFFERENCE yields


Product
 PRODUCT yields all possible pairs of rows from two tables—also known as the Cartesian
product. Therefore, if one table has 6 rows and the other table has 3 rows,the PRODUCT yields a
list composed of 6 . 3 = 18rows.
 The effect of a PRODUCT operation is shown in Figure 3.9.
 PRODUCT is denoted by the multiplication symbol *.
 The PRODUCT of the CUSTOMER and AGENT relations would be written as follows:
 customer * agent
 A Cartesian product produces a set of sequences in which every member of one set is
 paired with every member of another set. In terms of relations, this means that every
 tuple in one relation is paired with every tuple in the second relation.

FIGURE 3.9 PRODUCT

PRODUCT yields

Join
 JOIN allows information to be intelligently combined from two or more tables.
 JOIN is the real power behind the relational database, allowing the use of independent
 tables linked by common attributes.
 The CUSTOMER and AGENT tables shown in
 Figure 3.10 will be used to illustrate several types of joins.

34 | P a g e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

FIGURE 3.10 TWO TABLES THAT WILL BE USED IN JO IN ILLUSTRATIONS

Tablename:CUSTOMER Tablename:AGENT

 A natural join links tables by selecting only the rows with common values in their common
 attribute(s). A natural join is the result of a three-stage process:
 First, a PRODUCT of the tables is created, yielding the results shown in
 Figure 3.11.
FIGURE 3.11 NATURAL JOIN,STEP 1:PRODUCT

 Second, a SELECT is performed on the output of Step 1 to yield only the


 rows for which the AGENT_CODE values are equal. The common columns
 are referred to as the join columns. Step 2 yields the results shown in
 Figure 3.12.

35 | P a g e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

FIGURE 3.12 NATURAL JOIN,STEP 2: SELECT


 3.A PROJECT is performed on the results of Step 2 to yield a single copy of each
 attribute, thereby eliminating duplicate columns. Step 3 yields the output shown
 in Figure 3.13.

FIGURE 3.13 NATURAL JOIN,STEP 3: PROJECT

 A left outer join yields all of the rows in the CUSTOMER table, including those that
 do not have a matching value in the AGENT table. An example of such a join is shown
 in Figure 3.14.


Divide
 The DIVIDE operator is used to answer questions about one set of data being
 Associated with all values of data in another set of data.
 The DIVIDE operation uses one 2-column table (Table 1) as the dividend and one
 single-column table (Table 2) as the divisor.
 For example, Figure 3.16 shows a list of customers and the products purchased in
 Table 1 on the left. Table 2 in the center contains a set of products that are of interest
 to the users.
 A DIVIDE operation can be used to determine which customers, if any, purchased
36 | P a g e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

 every product shown in


 Table 2. In the figure, the dividend contains the P_CODE and CUS_CODE columns.
 The divisor contains the P_CODE column.
 The tables must have a common column—in this case, the P_CODE column.
 The output of the DIVIDE operation on the right is a single column that contains all values from
the second column of the divid end (CUS_CODE) that are associated with every row in the
divisor.
FIGURE 3.16 DIVIDE

DIVIDE yields

 Using the example shown in Figure 3.16, note the following:


2.7 DATA DICTIONARY AND THE SYSTEM CATALOG
 The data dictionary provides a detailed description of all tables in the database created
 by the user and designer. Thus, the data dictionary contains at least all of the attribute
 names and characteristics for each table in the system.
 In short, the data dictionary contains metadata—data about data. Using the small database
presented in Figure 3.3, you might picture its data dictionary as shown in Table 3.6.
 data dictionary A DBMS component that stores metadata— data about data. Thus, the data
dictionary contains the data
 definition as well as their characteristics and relationships. A data dictionary may also include
data that are external to the DBMS. Also known as an information resource dictionary. See also
active data dictionary, metadata, and passive
 data dictionary. system catalog A detailed system data dictionary that describes all objects in a
database.

37 | P a g e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

A SAMPLE DATA DICTIONARY


TABLE ATTRIBUTE NAME CONTENTS TYPE FORMAT RANGE REQUIR PKORF FK
NAME ED K REFERENC
ED TABLE
CUSTOME CUS_CODE Customer CHAR(5) 99999 10000– Y PK
R account 99999
code
CUS_LNAME Customer VARCHAR Xxxxxxxx Y
last name (20)
CUS_FNAME Customer VARCHAR Xxxxxxxx Y
first name (20)
CUS_INITIAL Customer CHAR(1) X
initial
CUS_RENEW_DAT Customer DATE dd-mmm-
E insurance yyyy
renewal
date
AGENT_CODE Agent code CHAR(3) 999 FK AGENT
AGENT AGENT_CODE Agent code CHAR(3) 999 Y PK
AGENT_AREACOD Agent are a CHAR(3) 999 Y
E code
AGENT_PHONE Agent CHAR(8) 999–9999 Y
telephone
number
AGENT_LNAME Agent last VARCHAR Xxxxxxxx Y
name (20)
AGENT_YTD_SLS AgenT year- NUMBER( 9,999,999
to-date sales 9,2) .99
2.8 RELATIONSHIPS

 A relationship describes an association among entities. For example, a relationship exists


between customers and agents that can be described as follows: an agent can serve many
customers, and each customer may be served by one agent.
38 | P a g e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

 Data models use three types of relationships:


 ONE-TO-MANY,
 MANY-TO-MANY,
 ONE-TO-ONE.
The following examples illustrate the distinctions among the three relationships. •

ONE-TO-MANY (1:M OR 1..*) RELATIONSHIP.

 A painter creates many different paintings, but each is painted by only one painter. Thus, the
painter (the “one”) is related to the paintings (the “many”).
 Therefore, database designers label the relationship “PAINTER paints PAINTING” as 1:M.
 Note that entity names are often capitalized as a convention, so they are easily identified.
 Similarly, a customer (the “one”) may generate many invoices, but each invoice (the “many”) is
generated by only a single customer.
 The “CUSTOMER generates INVOICE” relationship would also be labeled 1:M. •

MANY-TO-MANY (M:N OR *..*) RELATIONSHIP.

 An employee may learn many job skills, and each job skill may be learned by many employees.
 Database designers label the relationship “EMPLOYEE learns SKILL” as M:N. Similarly,
 a student can take many classes and each class can be taken by many students, thus yielding the
M:N label for

ONE-TO-ONE (1:1 OR 1..1) RELATIONSHIP.

A retail company’s management structure may require that each of its stores be managed by a single
employee. In turn, each store manager, who is an employee, manages only a single store.

2.9 DATA REDUNDANCY REVISITED


Data Redundancy Revisited in DBMS
 Data Redundancy refers to the unnecessary duplication of data within a database or across
multiple databases. It occurs when the same piece of data is stored in two or more places.
Revisiting this concept in the context of modern Database Management Systems (DBMS)
reveals how it impacts efficiency, data integrity, and design practices.
What is Data Redundancy?
 Data redundancy happens when the same data exists in multiple locations. For example, in a
university database, if a student's address is stored in multiple tables (student info, exam records,
and financial records), any change in the address requires updates in all places—else
inconsistencies may arise.
Types of Redundancy
 Unintentional Redundancy:
o Caused by poor database design.
o Leads to data anomalies and storage inefficiency.
 Intentional Redundancy:
o Used deliberately for performance (e.g., caching, denormalization).
o Helps in read-heavy systems but must be handled carefully.
Problems Caused by Data Redundancy
 Increased Storage Costs: More disk space is used.
39 | P a g e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

 Data Inconsistency: Updates in one location but not others lead to incorrect data.
 Update Anomalies: Multiple updates required for one change.
 Insert/Delete Anomalies: Difficulty in inserting or deleting data due to dependencies.
How DBMS Handles Redundancy
Normalization
 Process of organizing data to reduce redundancy.
 Breaks a database into smaller, related tables (1NF, 2NF, 3NF, etc.).
 Example:
 Before: A single table with student, course, and teacher info.
 After: Separate tables for Students, Courses, and Teachers with foreign key relations.
Data Integrity Constraints
 Primary Key: Ensures each record is unique.
 Foreign Key: Maintains referential integrity.
 Unique Constraints: Prevent duplication of values.
Database Design Techniques
 Use of Entity-Relationship (ER) models to capture logical structure.
 Tools like ER diagrams help visualize and reduce overlap in data.
 Trade-offs in Modern Systems
 In distributed or big data systems (like NoSQL databases), some redundancy is often intentional
to:
 Improve performance (fast reads).
 Enable high availability and fault tolerance.

2.10 INDEXES
 Indexes in a Database Management System (DBMS) are special data structures that improve the
speed of data retrieval operations on a database table at the cost of additional space and
maintenance overhead.
What is an Index?
 An index is like a table of contents in a book—it helps you find information quickly without
scanning the whole thing. In databases, an index allows the DBMS to find rows more efficiently,
especially during SELECT queries.
How Indexes Work
 When you create an index on one or more columns of a table, the DBMS creates a
 data structure (typically a B-Tree or Hash Table) that stores:
 The values of the indexed column(s)
 Pointers to the rows where those values appear
Types of Indexes
 Type  Description
 Automatically created on a table's primary key; values are
 Primary Index
unique and sorted.
 Unique Index  Ensures all values in the indexed column are unique.
 Sorts the actual table data in the order of the index; only one per
 Clustered Index
table.
 Maintains a separate structure from the table; can have multiple
 Non-Clustered Index
per table.
 Composite Index  Index on two or more columns.
 Full-Text Index  Used for text searching, especially in large strings or documents.

40 | P a g e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

 Type  Description
 Bitmap Index  Uses bitmaps for quick filtering, especially in data warehousing.
 Function-based Index  Index created on expressions or functions applied to columns.
Benefits of Using Indexes
 Faster query performance (especially for SELECT, WHERE, JOIN, and ORDER BY)
 Efficient filtering and sorting
 Supports quick searches on large datasets
Drawbacks / Limitations
 Extra disk space required to store indexes
 Slower write operations (INSERT, UPDATE, DELETE) due to index maintenance
 Over-indexing can degrade performance
 Not always used by the query planner if not selective enough.
2.11 codd's rules
 In 1985, Dr. E. F. Codd published a list of 12 rules to define a relational database
system.
 Dr. Codd’s list, shown in Table 3.8, is a frame of reference for what a truly relational
 database should be. Bear in mind that even the dominant database vendors do not fully support all
12 rules.


2.11 ENTITY RELATIONSHIP MODEL
41 | P a g e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

 Entity Relationship Model (ER Model)


 The entity-relationship data model perceives the real world as consisting of basic objects, called
entities and relationships among these objects.
 It was developed to facilitate database design by allowing specification of an enterprise schema
which represents the overall logical structure of a data base.

 Main Features of ER-MODEL:


o Entity relationship model is a high level conceptual model
o It allows us to describe the data involved in a real world enterprise in terms of objects
andtheir relationships.
o It is widely used to develop an initial design of a database
o It provides a set of useful concepts that make it convenient for a developer to move from a
basic set of information to a detailed and description of information that can be easily
implemented in a database system
o It describes data as a collection of entities, relationships and attributes.
Basic Concepts:
 The E-R data model employs three basic notions : entity sets, relationship sets and
attributes.
Entity Sets:
 An entity is a “thing” or “object” in the real world that is distinguishable from all other objects.
For example, each person in an enterprise is an entity.
 An entity has a set properties and the values for some set of properties may uniquely identify an
entity.
 BOOK is entity and its properties (called as attributes) bookcode, booktitle, price etc.An entity set
is a set of entities of the same type that share the same properties, or attributes. The set of all
persons who are customers at a given bank.

Attributes:
 An entity is represented by a set of attributes. Attributes are descriptive properties possessed
byeach member of an entity set.
 Customer is an entity and its attributes are customerid, custmername, custaddress etc.An
attribute as used in the E-R model, can be characterized by the following attribute types.
Simple and Composite Attribute:
 Simple attributes are the attributes which can’t be divided into sub parts, e.g. customerid, empno
Composite attributes are the attributes which can be divided into subparts, e.g. name consisting
offirst name, middle name, last name and address consisting of city, pincode, state.
Single-Valued and Multi-Valued Attribute:
 The attribute having unique value is single –valued attribute, e.g. empno, customerid, regdno etc.
 The attribute having more than one value is multi-valued attribute, eg: phone-no, dependent
name, vehicle.
Derived Attribute:
 The values for this type of attribute can be derived from the values of existing attributes, e.g. age
which can be derived from currentdate – birthdate and experience_in_year can be calculated as
currentdate-joindate.
NULL Valued Attribute:
 The attribute value which is not known to user is called NULL valued attribute.
42 | P a g e
PADMAVANI ARTS & SCIENCE COLLEGE FOR WOMEN (AUTONOMOUS)

43 | P a g e
ER Diagrams

ER Diagrams

 An ER diagram shows the relationship among entity sets


 ER Diagram is a visual representation of data that describes how data is related
to each other.
 Entity relationship diagram displays the relationships of entity set stored
sto in a
database.
 In other words, we can say that ER diagrams help you to explain the logical
structure of databases..

ER diagram symbols
Symbol Name

Entity

Weak Entity

Relationship

Weak Relationship

Attribute / Simple
Composite / Single
valued Attributes

Key Attribute

Multi valued Attributes

Derived Attributes
Partial Key Attributes

Generalization /
IS A Specialization

Total Generalization

Super class / Sub class

Union / Category

Components of ER Diagram
 Entitiy, Attributes, Relationships etc form the components of ER Diagram and
there are defined symbols and shapes to represe
represent
nt each one of them.
Entity
 Simple rectangular box represents an Entity.

Relationships between Entities - Weak and Strong


 Rhombus is used to setup relationships between two or more entities.
 Weak Relationships are connections between a weak entity and iits
ts owner.

 In abovee example, "Trans No" is a discriminator within a group of transactions in


an ATM.
Attributes for any Entity
 Ellipse is used to represent attributes of any entity. It is connected to the entity.

Weak Entity
 A weak entity is a type of entity which doesn't have its key attribute.
 It can be identified uniquely by considering the primary key of another entity.
entity
 They don't have primary keys, and have no meaning in the diagram without
their parent entity.
 A weak Entity is represented using double rectangular boxes. It is generally
connected to another entity.

Key Attribute for any Entity


 To represent a Key attribute, the attribute name inside the Ellipse is underlined.
(Primary key)

Derived Attribute for any Entity


 Derived attributes are re those which are derived based on other attributes, for
example, age can be derived from date of birth.
 To represent a derived attribute, another dotted ellipse is created inside the main
ellipse.

Multivalued Attribute for any Entity


 Multivalued attributes
butes are those that are can take on more than one value.
 Double Ellipse, one inside another, represents the attribute which can have
multiple values.
Sample ER diagrams
1) Library Management System

2) Student management System

3)
Ho
spit
al
Ma
nag
em
ent
Sys
tem
Assignments on ER diagrams

 Employee database system


 Banking system
 Exam database system
 Hotel Management system
 Anna university database system
 Airline Reservation system
 Railway reservation system etc.,

Enhanced ER model / Extended ER model

 ER model is supported with the additional semantic concepts is called as


Extended / Enhanced Entity Relationship Model
 EER model includes following concepts
o Specialization
o Generalization
o Aggregation
o Sub class and Super Class
o Union or Category
 Enhanced entity-relationship diagrams are advanced database diagrams very
similar to regular ER diagrams which represent requirements and complexities
of complex databases.
 As the complexity of data increased in the late 1980s, it became more and more
difficult to use the traditional ER Model for database modelling. Hence some
improvements or enhancements were made to the existing ER Model to make it
able to handle the complex applications better .

Features of EER Model

 EER creates a design more accurate to database schemas.


 It reflects the data properties and constraints more precisely.
 It includes all modeling concepts of the ER model.
 Diagrammatic technique helps for displaying the EER schema.
 It includes the concept of specialization and generalization.
 It is used to represent a collection of objects that is union of objects of different of
different entity types.

1. Specialization

 Specialization is the process of defining a set of subclasses of an entity


 Specialization is a process that defines a group entities which is divided into sub
groups based on their characteristic.
 It is a top down approach, in which one higher entity can be broken down into
two lower level entity.
 It maximizes the difference between the members of an entity by identifying the
unique characteristic or attributes of each member.
 It defines one or more sub class for the super class and also forms the
superclass/subclass relationship.

 For example1
 In the above example, Employee can be specialized as Developer or Tester, based
on what role they play in an Organization.
 Inverted triangle stands for “is a” relationship for both specialization and
generalization.
 Example2
o In university, student belongs to 2 categories “Undergraduate” &
“Postgraduate”. Both categories of students may have common attributes
as well as unique attributes(UG students in Hostel, PG students in Office).

Name roll Address

Student
Top down

IS A

room_no office_no

UG PG

UG Entity Attributes PG entity Attributes


roll, Name, Address, room_no roll, Name, Address, office_no
Example 3:

Name city street

person
Top down

IS A
salary mark

Employee Student

IS A

Officer Engineer Teacher

role dept id dept subject

2. Generalization

 Generalization is the process of generalizing the entities which contain the


properties of all the generalized entities.
 It is a bottom up approach, in which two lower level entities combine to form a
higher level entity.
 Generalization is the reverse process of Specialization.
 It defines a general entity type from a set of specialized entity type.
 It minimizes the difference between the entities by identifying the common
features.
For example:

In the above example, Tiger, Lion, Elephant can all be generalized as Animals.
Example
 Consider 2-entity sets CAR & TRUCK

No. of
Max_speed
Passenger

CAR

vehicle_id price

Licence_no

No. of wheels weight

TRUCK

vehicle_id price

Licence_no

 In above 2 entity set, vechile_id, price & Licence_no are common attributes.
 Hence generalize them into a single super class.

vehicle_id price Licence_no

Vehicle
Bottom up
Generalization Constraints
 Constraints are application for generalization and specialization.
 There are three categories of constraints
o Determine which entities can be member of a given lower –level entity set
 Conditional defined
 User Defined
o Determine entities belong to more than one lower level entity set
 Disjoint
 Overlapping
o Determine participation/belonging of higher level entity
 Total generalization/specialization
 Partial generalization /specialization
a) Determine which entities can be member of a given lower –level entity set
i. Conditional defined
 Condition is defined, based on that members of lower-level entities is
evaluated or joined.
account_type

Account

IS A
if account_type=”saving” if account_type=”current”

saving_account current_account

ii. User Defined


o Type of the constraints / members of entities are defined by the user

Employee

IS A

Team 1 Team 2 Team 3


If an employee joins an entity “employee”, Team Incharge will assign to
any one of the 3 teams.
 It is defined by the user.
b) Determine entities belong to more than one lower level entity set
i. Disjoint
 Disjoint constraints specifies that an entity belong to only one lower-level
entity set.
 It is represented user the ER notation

IS A

 Example
account_type

Account

IS A

saving_account current_account

 User can join only one of the lower-level entity

ii. Overlapping
 In overlapping generalization, same entity belongs to more than one lower-
level entity set.
 It is represented user the ER notation

IS A
Example

Person

IS A

customer employee

 A person can be customer & employee.


 Can participate in more than one entity of lower level.

c) Determine participation/belonging of higher level entity


i. Total generalization/specialization
 Each entity at higher level must belong to a lower-level entity set.
 Total generalization is represented using double line
 Example: Each account must belong to any one of the lower level enity.

Account

IS A

saving_account current_account

ii. Partial generalization /specialization


 Some entities of higher level may not belong to any lower level entity set.
 Partial generalization is default
 The work team entity set illustrates a partial specialization. Since employees
are assigned to a team only after three months on the job, some employee
entities may not be members on any of the lower level team entity sets.
3. Aggregation
 Aggregation is an abstraction through which relationship are treated as higher-
level entities.
 Aggregation is used to avoid redundant information.
 Aggregation is a process that represent a relationship between a whole object
and its component parts.
 It abstracts a relationship between objects and viewing the relationship as an
object.
 It is a process when two entity is treated as a single entity.

In the above example, the relation between College and Course is acting as an Entity in
Relation with Student.

Example:

ER diagram with redundant relationship

Job

Work
Job on Job

Man
ages

Job
ER Diagram with Aggregation

Job

Work
Job on Job

Aggregation

Man
ages

Job
3. Sub Class and Super Class
 Sub class and Super class relationship leads the concept of Inheritance.

 The relationship between sub class and super class is denoted with symbol.
1. Super Class
 Super class is an entity type that has a relationship with one or more subtypes.
 An entity cannot exist in database merely by being member of any super class.
For example: Shape super class is having sub groups as Square, Circle, Triangle.
2. Sub Class
 Sub class is a group of entities with unique attributes.
 Sub class inherits properties and attributes from its super class.
For example: Square, Circle, Triangle are the sub class of Shape super class.

5. Category or Union
 Category represents a single super class or sub class relationship with more than
one super class.
 It can be a total or partial participation.
For example Car booking, Car owner can be a person, a bank (holds a possession
on a Car) or a company. Category (sub class) → Owner is a subset of the union of
the three super classes → Company, Bank, and Person. A Category member must
exist in at least one of its super classes.
ER to Relational Mapping
 ER Model can be represented using ER Diagrams which is a great way of
designing and representing the database design in more of a flow chart form.
 It is very convenient to design the database using the ER Model by creating an
ER diagram and later on converting it into relational model to design your tables.
 Examples of ER diagrams and convert it into relational model schema, hence
creating tables in RDBMS.
1. Mapping Entity
 Entity in ER Model is changed into tables, for every Entity in ER model, a
table is created in Relational Model. (Entity  Table)
 The attributes of the Entity gets converted to columns of the table. (Attributes
 Columns of the Table)
 The primary key specified for the entity in the ER model, will become the
primary key for the table in relational model.
 For example, for the below ER Diagram in ER Model,

 A table with name Student will be created in relational model, which will have 4
columns, id, name, age, address and id will be the primary key for this table.
Table Name: Student
id name age address
Example 2

Entity Mapping Process (Algorithm)

 Create table for each entity.


 Entity's attributes should become fields of tables with their respective data types.
 Declare primary key.

2. Mapping Relationship

 In ER diagram, diamond/rhombus used to represent a relationship between two


entities.
 In the ER diagram below, have two entities Teacher and Student with a
relationship between them.
Example 1:

 Here, Entity gets mapped to table,


o hence we will create table for Teacher and a table for Student with all the
attributes converted into columns.
 Now, an additional table will be created for the relationship,
o for example StudentTeacher or give it any name you like.
o This table will hold the primary key for both Student and Teacher, in a
tuple to describe the relationship, which teacher teaches which student.
 If there are additional attributes related to this relationship, then they become the
columns for this table, like subject name.
 Also proper foreign key constraints must be set for all the tables.
Example 2

 Project(ProjId,, Name, TotalCost, StartDate)


 Parts(UPC,, PartName, Weight, WSPrice)
 Suppliers(SupId,, Name, Address)
 Sold(ProjId, UPC, SupId
SupId, Date, Price)

Example 3:

 S2000Courses (CrsCode
CrsCode, SectNo, Enroll)
 Professor (Id, DeptId, Name)
 Teaching (CrsCode, SecNo
SecNo, Id, RoomNo)
4:Example

Relationship Mapping Process (Algorithm)


 Create table for a relationship.
 Add the primary keys of all participating Entities as fields of table with their
respective data types.
 If relationship has any attribute, add each attribute as field of table.
 Declare a primary key composing all the primary keys of participating entities.
 Declare all foreign key constraints.

3. Mapping Weak Entity


 Weak entity-sets depend on at least one strong entity-set
 Identifying entity-set, or owner entity-set
 Relationship between the two called the identifying relationship
 A weak entity set is one which does not have any primary key associated with it.
Mapping Process
 Create table for weak entity set.
 Add all its attributes to table as field.
 Add the primary key of identifying entity set.
 Declare all foreign key constraints.
Example 1

Example 2

Example 3
Mapping Hierarchical Entities

ER specialization or generalization comes in the form of hierarchical entity sets.

Mapping Process
 Create tables for all higher
higher-level entities.
 Create tables for lower--level entities.
 Add primary keys of higher
higher-level entities in the table of lower-level
vel entities.
 In lower-level
level tables, add all other attributes of lower
lower-level
level entities.
 Declare primary key of higher
higher-level
level table and the primary key for lower-level
lower
table.
 Declare foreign key constraints.
(or)

Recall

 Entity gets converted into Table, with all the attributes becoming fields(columns)
in the table.
 Relationship between entities is also converted into table with primary keys of
the related entities also stored in it as foreign keys.
 Primary Keys should be properly set.
 For any relationship of Weak Entity, if primary key of any other entity is
included in a table, foreign key constraint must be defined.
Text book Example:

Result
EMPLOYEE

Fname Minit Lname Ssn Bdate Address Sex Salary Super_ssn Dno

DEPARTMENT

Dname Dnumber Mgr_ssn Mgr_start_date

DEPT_LOCATION
Dnumber Dlocation

PROJECT

Pname Pnumber Plocation Dnum

WORKS_ON
Essn Pno Hours

DEPENDENT

Essn Dependent_name Sex Bdate Relationship

You might also like