0% found this document useful (0 votes)
49 views89 pages

DBMS PPT Unit I

Sri Manakula Vinayagar Engineering College ppt for Database Management Systems developed by the college lecturer itself

Uploaded by

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

DBMS PPT Unit I

Sri Manakula Vinayagar Engineering College ppt for Database Management Systems developed by the college lecturer itself

Uploaded by

btechit240937
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

U23CSTC04 – Database Management Systems

II Year / III Semester


N. Kalaiselvi, Assistant Professor, Department of IT,SMVEC
DBMS – Units
Overview
01 02
INTRODUCTION DATABASE
LANGUAGES

03 04 05
RELATIONAL- TRANSACTIONS NoSQL Databases
DATABASE DESIGN
AND DATA STORAGE
Course Outcomes
After completion of the course, the students will be able to

CO1 - Explain the concepts of Database Management System and develop Entity Relationship model
and Relational Models for a given application (K2)

CO2 - Manipulate and build database queries using Structured Query Language and relational algebra (K3)

CO3 - Use data normalization principles to develop a normalized database for a given application. (K3)

CO4 - Illustrate various transactions and recovery techniques (K2)

CO5 - Apply tools like NoSQL, MongoDB, Cassandra on real time applications (K3)
Syllabus
Unit I INTRODUCTION
Database Systems– Data Models – Database System Architecture - Entity-Relationship Model - ER
Diagram- Extended ER Model –ER into Relational Model - Relational Model: Structure of Relational
Databases, Database Schema, Keys, Tables.

Unit II DATABASE LANGUAGES


Relational Algebra – Extended-Relational Algebra - Relational Calculus –SQL: Introduction – DDL – DML –
Integrity Constraints -Set Operations -Joins – Nested Queries -View- Trigger - Stored Procedures .

Unit III RELATIONAL-DATABASE DESIGN AND DATA STORAGE


Relational Database Design: Domain and Data Dependency – Lossless Design – Armstrong’s Axioms -
Functional Dependencies – Normal Forms – 1NF, 2NF, 3NF, BCNF, 4NF.
Data Storage: RAID - File Organization – Indexing: Types of Indexing.

Unit IV TRANSACTIONS
Transaction concepts and states– Concurrent Execution - Serializability - Query Processing -
Concurrency Control: Lock based Protocol - Timestamp based Protocol - Recovery System: – Log-
Based Recovery – Shadow Paging.

Unit V NOSQL DATABASES


NoSQL – Document Database: MongoDB - Multi-dimensional: Cassandra
Text Books and
Text Books: References
1. Silberschatz, Korth, Sudarshan, Database System Concepts, 7th Edition – McGraw-Hill Higher
Education, International Edition, 2019.
2. Ramez Elmasri, and Shamkant B. Navathe, Fundamentals of Database Systems (7th
edition), ,Publisher: Pearson,2016.
3. Raghu Ramakrishnan, “Database Management Systems”, Fourth Edition, McGraw-Hill College
Publications, 2015.
Reference Books:
1. Date C J, Kannan A and Swamynathan S, “An Introduction to Database Systems”, 8th Edition,
Pearson Education, New Delhi, 2006.
2. Alan Beaulieu, “Mastering SQL Fundamentals”, Second Edition, O’Reilly,2009
3. Kristina Chodorow; Shannon Bradshaw, “MongoDB: The Definitive Guide”, 3rd Edition, O'Reilly
Media, Inc., 2018.
4. Pramod J. Sadalage (Author), Martin Fowler, “NoSQL Distilled: A Brief Guide to the Emerging World
of Polyglot Persistence”, 1stEdition, Kindle Edition
Website References:
• http://www.database.com/
• http://cassandra.apache.org/
• https://www.mongodb.com/
Data
Data
● Data can be facts related to any object

● Example

○ stdno, std_name, dept, year


○ name, age, height, weight
● Mobile Contact

○ NAME

○ MOBILE
NUMBER
○ OFFICE

○ EMAIL-ID
What is Data
• Data can be facts related to any object
• Raw facts can be processed by computing machine.
• Collection of facts from which conclusions may be drawn.
• Data can be represented in the form of:
• numbers and words which can be stored in computer’s language.

What is Information
• Systematic and meaningful form of data.
• Knowledge acquired through study or experience.
• Information helps human beings in their decision making.
Is a collection of inter-related data and set of
programs to access those data

Is used to retrieve, insert and delete the data

Database ? efficiently.

Is used to organize the data in the form of a


table, schema, views, and reports, etc
Database Example

Bank Database

Student Database
DBMS

Database management system is


software that is used to manage
the database.
Database Management System - Tools
Commonly Used DBMS
List of databases used by Internet’s biggest websites

• Google uses BigTable

• Facebook uses
• Hive - Data warehouse for Hadoop, supports tables and a variant
of SQL called hiveQL and
• Cassandra - Multi-dimensional, distributed key-value store for
Facebook's private messaging.

• Yahoo uses Modified PostgreSQL.

• YouTube uses MySQL but they are moving to Google's BigTable.

• Twitter and Wikipedia uses MySQL.


Database Management System
● Database management system is a software which is used to manage the
database. For example: MySQL, Oracle, etc are a very popular commercial
database which is used in different applications.
● DBMS provides an interface to perform various operations like database creation,
storing data in it, updating data, creating a table in the database and a lot more.
● It provides protection and security to the database. In the case of multiple users,
it also maintains data consistency.
DBMS allows users the following
tasks:
● Data Definition: It is used for creation, modification, and removal of definition that defines
the organization of data in the database.
● Data Updation: It is used for the insertion, modification, and deletion of the actual data in
the database.
● Data Retrieval: It is used to retrieve the data from the database which can be used by
applications for various purposes.
● User Administration: It is used for registering and monitoring users, maintain data
integrity, enforcing data security, dealing with concurrency control, monitoring performance
and recovering information corrupted by unexpected failure.
Advantages of
DBMS

Data sharing Controls database Easily Maintenance


redundancy:
Authorized users of an Due to the centralized
organization can share It stores all the data in nature of the database
the data among one single database file system.
multiple users. and that recorded data is
placed in the database
Disadvantages of
DBMS

Cost of Hardware and Size Complexity


Software
It occupies a large Database system
It requires a high speed space of disks and
of data processor and
creates additional
large memory to run complexity and
large memory size to run them efficiently.
DBMS software. requirements.
Data Models
● A data model is a collection of conceptual tools for describing

○ Data

○ data relationships

○ data semantics

○ consistency constraints.

Data Models - Types


● Relational model
● Entity-Relationship data model (mainly for database design)
● Object-based data models (Object-oriented and Object-relational)
● Semi-structured data model (XML)
● Other older models:
○ Network model
○ Hierarchical model
Entity-Relationship Model
● An Entity is an object that exists and is distinguishable from other
objects.

○ Example:

■ Person, Company, Event

● Entity is characterized by a set of attributes


● Relationship – describes an interconnection between different entities
● Entity Set – a set of entities that are characterized by the same entity
definition
● Relationship Set – a set of relationships of the same type
Relational Model
● An enterprise is represented as a set of relations
● Domain – is a set of atomic values. Each domain has a NULL value.
● Data type – Description of a form that domain values can be represented.
● Relation is a subset of a cartesian product of one or more domains
● The elements of relations are called tuples. Each element in the cartesian
product is called attribute.
Relational Database
Object Oriented Model

● Database functionalities to Object Programming Language

● An enterprise is described as a collection of objects and a


collection of algorithms that work with objects
● Example: Person is an object.
● Object is characterized by a set of public attributes.
Object Oriented Model
● Applications may refer only to public attributes; private attributes.
● Algorithms that implement the object may refer to private attributes; a set of
protected attributes and a set of methods
● Attribute of an object can be another object
● Objects are nested into a hierarchy and can inherit attributes of their parents
● Encapsulation, set of Methods/Access functions
● Inheritance – Defining new classes like old classes

Example Class Person


{
public:
Person();
~Person();
float GetSalary();
float PutSalary(float&);
string Name;
int SSN;
date BirthDate;
private:
float salary;
}
Hierarchical Model

● Data organized as Tree-like Structure

● Data is stored as records which are connected to


one another through links.

● Data is sorted hierarchically, using a downward


tree.

● Uses pointers to navigate between stored data.

● First DBMS model.


Hierarchical Model

● Components
● Boxes - which correspond to record types
● Lines - which correspond to links
● Each entity has only one parent but can have several
children.
● At the top hierarchy there is only one entity which is called
root.
Network Model

● Like the hierarchical model


● Model uses pointers toward stored data.
● It does not necessarily use a downward tree structure.
● Each record have multiple parent and child records
● Entities are organized in a graph
● Viewed as a graph in which object types are nodes and relationship types
are arcs
● Some entities can be accessed through several path.
Network Model
XML: Extensible Markup Language

● Defined by the WWW Consortium (W3C)


● Is a document markup language not a database language
● The ability to specify new tags, and to create nested tag structures made
XML a great way to exchange data, not just documents
● XML has become the basis for all new generation data interchange formats.
● A wide variety of tools is available for parsing, browsing and querying XML
documents/data
Database
• DBMS contains information about an enterprise
• Collection of interrelated data
• Set of programs to access the data
• An environment that is both convenient and efficient to use

Database Applications
• Banking: all transactions
• Airlines: reservations, schedules
• Universities: registration, grades
• Sales: customers, products, purchases
• Online retailers: order tracking, customized recommendations
• Manufacturing: production, inventory, orders, supply chain
• Human resources: employee records, salaries, tax deductions

• Databases touch all aspects of our lives


What is DBMS ?

• DBMS - Database Management System.


• DBMS is a software system for creating, organizing and
managing the database.
• It is an environment to the user to perform operations on the
database for creation, insertion, deletion, updating and retrieval
of data.
Purpose of Database
• In early days, database applications wereSystems
built on the – Atomicity of updates
top of the file systems – Failures may leave database in an
• Drawbacks of using file systems to store data: inconsistent state with partial updates
– Data redundancy and inconsistency carried out
• Multiple file formats, duplication of – Example:
information in different files – Transfer of funds from one account
– Difficulty in accessing data to another should either complete or
• Need to write a new program to carry out not happen at all
each new task - Concurrent access by multiple users
– Data isolation — multiple files and formats – Concurrent accessed needed for performance
– Integrity problems – Uncontrolled concurrent accesses can lead to
• Integrity constraints (e.g. account balance > inconsistencies
0) become “buried” in program code rather • Example: Two people reading a balance
than being stated explicitly and updating it at the same time
• Hard to add new constraints or change -- Security problems
existing ones • Hard to provide user access to some, but not
all, data
Database systems offer solutions to all the above
problems
Level of Abstraction
Level of
Abstraction
• Physical: This is the lowest level of data abstraction. It tells us how the
data is actually stored in memory.
• Logical: The next level of data abstraction. It tells us what data is actually
stored in the database in the form of tables. It also stores the relationship
among the data entities in relatively simple structures.
• View: This is the highest level of abstraction. Only a part of the actual
database is viewed by the users. This level exists to ease the accessibility
of the database by an individual user.
Instance and
Schema
• Schema – the overall logical structure of the database

• Example: The database consists of information about a set


of customers and accounts and the relationship between
them)
• Instance – The data stored in database at a particular moment
of time is called instance of database.
• Physical Data Independence – the ability to modify the physical
schema without changing the logical schema
Database
Architecture
Database
Architecture
• Has 4 Parts

• Database Users

• Query Processor

• Storage Manager

• Disk Storage
Database-Users
Bank Tellers, Reservation Clerks
Naïve User Are unsophisticated users who interact with the
system by invoking one of the application programs
that have been written previously.

are computer professionals who write application programs.


Application
Application programmers can choose from many tools to develop
Programmers user interfaces. Rapid application development (RAD) tools are
tools that en- able an application programmer to construct forms
and reports with minimal programming effort.

interact with the system without writing programs. In- stead, they
Sophisticated form their requests either using a database query language or by
User using tools such as data analysis software. Analysts who submit
queries to explore data in the database fall in this category.

are sophisticated users who write specialized database


applications that do not fit into the traditional data-processing
Specialized framework. Among these applications are computer-aided design
Users systems, knowledge- base and expert systems, systems that store
data with complex data types (for example, graphics data and
audio data), and environment-modeling systems.
Database
Database Administrator Users
A person who has such central control over the system is called a database administrator
(DBA). The functions of a DBA include:

• Schema definition
• Storage structure and access-method definition
• Schema and physical-organization modification
• Granting of authorization for data access
• Routine maintenance. Examples of the database administrator’s routine
maintenance activities are:
o Periodically backing up the database, either onto tapes or onto remote servers,
to prevent loss of data in case of disasters such as flooding.
o Ensuring that enough free disk space is available for normal operations, and
upgrading disk space as required.
o Monitoring jobs running on the database and ensuring that performance is not
degraded by very expensive tasks submitted by some users.
Query Processor
Query Processor

• It Includes
• DDL interpreter - interprets DDL statements and records the
definitions in the data dictionary.
• DML complier - translates DML statements in a query language
into an evaluation plan consisting of low-level instructions that the
query evaluation engine understands.

• A query can be translated into any of a number of alternatives


evaluation plans that all give the same result.
• DML complier performs query optimization, that is, it picks the
lowest cost evaluation plan from among the alternatives.

• Query evaluation engine, which executes low-level instructions


generated by the DML compiler.
Storage Manager
Storage Manager
Storage manager is a program module that provides the interface between the
low-level data stored in the database and the application programs and
queries submitted to the system. Includes

• Authorization and integrity manager, which tests for the satisfaction of


integrity constraints and checks authority to access the data.

• Transaction manager, which ensures that the database remains in a


consistent state despite system failures and that concurrent transaction
execution proceed without conflicting.

• File Manager, which manages the allocation of space on disk storage and
the data structures used to represent information stored on disk.

• Buffer manager, which is responsible for fetching data from disk storage
into main memory, and deciding what data to cache in main memory. It is
used to handle data sizes that are much larger than the size of main
memory.
Disk
Storage
Disk
Storage
The storage manager implements several data structures as part of the physical

system implementation.

Data files, which store the database itself.

Data Dictionary, which stores metadata about the structure of the

database, in particular the schema of the database.

Indices, which provide fast access to data items that hold particular values.
Entity Relationship (ER) Model - Basic Concepts
The ER model defines the conceptual view of a database. It works around real-world entities and the associations
among them. At view level, the ER model is considered a good option for designing databases.
Components of the ER Diagram
This model is based on three basic concepts:
○ Entities
○ Attributes
○ Relationships
Entity
• A real-world thing either living or non-living that is easily recognizable and non-recognizable. It is anything in
the enterprise that is to be represented in our database. It may be a physical thing or simply a fact about the
enterprise or an event that happens in the real world.
• An entity can be place, person, object, event or a concept, which stores data in the database. The characteristics
of entities are must have an attribute, and a unique key. Every entity is made up of some ‘attributes’ which
represent that entity.

Examples of entities:
• Person: Employee, Student, Patient
• Place: Store, Building
• Object: Machine, product, and Car
• Event: Sale, Registration, Renewal
• Concept: Account, Course
Entity set:
● Student
● An entity set is a group of similar kind of entities. It may contain entities with attribute sharing similar values. Entities
are represented by their properties, which also called attributes. All attributes have their separate values. For example, a
student entity may have a name, age, class, as attributes.
Attributes
• Entities are represented by means of their properties, called attributes. All attributes have values. For
example, a student entity may have name, class, and age as attributes.
• There exists a domain or range of values that can be assigned to attributes. For example, a student's
name cannot be a numeric value. It has to be alphabetic. A student's age cannot be negative, etc.

Types of Attributes
• Simple attribute − Simple attributes are atomic values, which cannot be divided further. For example, a
student's phone number is an atomic value of 10 digits.
• Composite attribute − Composite attributes are made of more than one simple attribute. For example, a
student's complete name may have first_name and last_name.
• Derived attribute − Derived attributes are the attributes that do not exist in the physical database, but
their values are derived from other attributes present in the database. For example, average_salary in a
department should not be saved directly in the database, instead it can be derived. For another example,
age can be derived from data_of_birth.
• Single-value attribute − Single-value attributes contain single value. For example −
Social_Security_Number.
• Multi-value attribute − Multi-value attributes may contain more than one values. For example, a
person can have more than one phone number, email_address, etc.
Relationship
• The association among entities is called a relationship. For example, an employee works at a department, a
student enrolls in a course. Here, Works_at and Enrolls are called relationships.

Relationship Set
• A set of relationships of similar type is called a relationship set. Like entities, a relationship too can have
attributes. These attributes are called descriptive attributes.

Degree of Relationship
• The number of participating entities in a relationship defines the degree of the relationship.
• Binary = degree 2
• Ternary = degree 3
• n-ary = degree
ER Diagrams Symbols & Notations
Following are the main components and its symbols in ER Diagrams:
• Rectangles: This Entity Relationship Diagram symbol represents entity types
• Ellipses : Symbol represent attributes
• Diamonds: This symbol represents relationship types
• Lines: It links attributes to entity types and entity types with other relationship types
• Primary key: attributes are underlined
• Double Ellipses: Represent multi-valued attributes
ER Diagrams

● Entity

● Attributes
Mapping Constraints
• A mapping constraint is a data constraint that expresses the number of entities to which another entity can be related via a
relationship set.
• It is most useful in describing the relationship sets that involve more than two entity sets.
• For binary relationship set R on an entity set A and B, there are four possible mapping cardinalities. These are as follows:
○ One to one (1:1)
○ One to many (1:M)
○ Many to one (M:1)
○ Many to many (M:M)
One-to-one
• In one-to-one mapping, an entity in E1 is associated with at most one entity in E2, and an entity in E2 is associated with at
most one entity in E1.
• Example: One student can register for numerous courses. However, all those courses have a single line back to that one
student.

One-to-many
• In one-to-many mapping, an entity in E1 is associated with any number of entities in E2, and an entity in E2 is associated
with at most one entity in E1.
• For example, one class is consisting of multiple students.
Many-to-one
• In one-to-many mapping, an entity in E1 is associated with at most one entity in E2, and an entity in E2 is associated with
any number of entities in E1.
• For example, many students belong to the same class.

Many-to-many
• In many-to-many mapping, an entity in E1 is associated with any number of entities in E2, and an entity in E2 is associated
with any number of entities in E1.
• For example, Students as a group are associated with multiple faculty members, and faculty members can be associated
with multiple students.
Participation Constraints
• Total Participation − Each entity is involved in the relationship. Total participation is represented by double
lines.
• Partial participation − Not all entities are involved in the relationship. Partial participation is represented by
single lines.
Extended ER Features
• The basic E-R concepts can model most database features, some aspects of a database may be more aptly expressed by certain
extensions to the basic E-R model. The extended E-R features are
• Specialization
• Generalization
• Attribute Inheritance
• Constraints on Generalizations
• Condition-defined
• User-defined
• Disjoint
• Overlapping
• Aggregation
● Specialization – The process of designating to sub
grouping within an entity set is called specialization. For
example, the “person” is distinguish in to whether they are
“employee” or “customer”.
● Formally specialization is depicted by a triangle component
labelled (is a), means the customer is a person.
● Sometime this ISA (is a) referred as a superclass-subclass
relationship. This is also used to emphasize on to creating
the distinct lower level entity sets.
● Generalization – generalization is relationship that exist
between higher level entity set and one or more lower level
entity sets. Generalization synthesizes these entity sets into
single entity set.
● Higher level and lower level entity sets – This property is
created by specialization and generalization. The attributes
of higher level entity sets are inherited by lower level entity
sets.
● For example: “customers” and “employee” inherits the
attributes of “person”.
Attribute inheritance
• A crucial property of the higher- and lower-level entities created by specialization and generalization is
attribute inheritance. The attributes of the higher-level entity sets are said to be inherited by the lower-level
entity sets.
• For example, student and employee inherit the attributes of person. Thus, student is described by its ID,
name, and address attributes, and additionally a tot cred attribute; employee is described by its ID, name,
and address attributes, and additionally a salary attribute

Constraints on Generalizations
• One type of constraint involves determining which entities can be members of a given lower-
level entity set. Such membership may be one of the following:
Condition-defined:
• In condition-defined lower-level entity sets, membership is evaluated on the basis of whether or not an
entity satisfies an explicit condition or predicate.
• For example, assume that the higher-level entity set student has the attribute student type. All student
entities are evaluated on the defining student type attribute. Only those entities that satisfy the condition
student type = “graduate” are allowed to belong to the lower-level entity set graduate student. All entities
that satisfy the condition student type = “undergraduate” are included in undergraduate student.
● User-defined. User-defined lower-level entity sets are not constrained by a membership condition; rather, the
database user assigns entities to a given entity set.
● For instance, let us assume that, after 3 months of employment, university employees are assigned to one of four
work teams. We therefore represent the teams as four lower-level entity sets of the higher-level employee entity set.
A given employee is not assigned to a specific team entity automatically on the basis of an explicit defining
condition. Instead, the user in charge of this decision makes the team assignment on an individual basis.

● A second type of constraint relates to whether or not entities may belong to more than one lower-level entity set
within a single generalization. The lower level entity sets may be one of the following:

● Disjoint. A disjointness constraint requires that an entity belong to no more than one lower-level entity set. In our
example, student entity can satisfy only one condition for the student type attribute; an entity can be either a
graduate student or an undergraduate student, but cannot be both.
● Overlapping. In overlapping generalizations, the same entity may belong to more than one lower-level entity set
within a single generalization. For an illustration, consider the employee work-team example, and assume that
certain employees participate in more than one work team. A given employee may therefore appear in more than
one of the team entity sets that are lower level entity sets of employee. Thus, the generalization is overlapping
• A final constraint, the completeness constraint on a generalization or specialization, specifies
whether or not an entity in the higher-level entity set must belong to at least one of the lower-level
entity sets within the generalization/specialization. This constraint may be one of the following:
• Total generalization or specialization: Each higher-level entity must belong to a lower-level entity
set.
• Partial generalization or specialization: Some higher-level entities may not belong to any lower-
level entity set.
ER into Relational Model (Reduction of ER diagram to Table)
• The database can be represented using the notations, and these notations can be reduced to a collection of tables.
• In the database, every entity set or relationship set can be represented in tabular form.
There are some points for converting the ER diagram to the table:
• Entity type becomes a table.
• In the given ER diagram, LECTURE, STUDENT, SUBJECT and COURSE forms individual tables.

• All single-valued attribute becomes a column for the table.


• In the STUDENT entity, STUDENT_NAME and STUDENT_ID form the column of STUDENT table. Similarly,
COURSE_NAME and COURSE_ID form the column of COURSE table and so on.

• A key attribute of the entity type represented by the primary key.


• In the given ER diagram, COURSE_ID, STUDENT_ID, SUBJECT_ID, and LECTURE_ID are the key attribute of the entity.

• The multivalued attribute is represented by a separate table.


• In the student table, a hobby is a multivalued attribute. So it is not possible to represent multiple values in a single column of
STUDENT table. Hence we create a table STUD_HOBBY with column name STUDENT_ID and HOBBY. Using both the
column, we create a composite key.

• Composite attribute represented by components.


• In the given ER diagram, student address is a composite attribute. It contains CITY, PIN, DOOR#, STREET, and STATE. In
the STUDENT table, these attributes can merge as an individual column.

• Derived attributes are not considered in the table.


• In the STUDENT table, Age is the derived attribute. It can be calculated at any point of time by calculating the difference
between current date and Date of Birth.
● Table structure for the given ER diagram is as below
Notations for modeling data using ER diagrams
Relational Model: Structure of Relational Databases, Database Schema,
Keys, Tables
Relational Model
● Relational Model (RM) represents the database as a collection of relations. A relation is
nothing but a table of values. Every row in the table represents a collection of related data
values. These rows in the table denote a real-world entity or relationship.
● The table name and column names are helpful to interpret the meaning of values in each row.
The data are represented as a set of relations. In the relational model, data are stored as tables.
However, the physical storage of the data is independent of the way the data are logically
organized.
Relational Model Concepts in DBMS
1. Attribute: Each column in a Table. Attributes are the properties which define a relation. e.g.,
Student_Rollno, NAME,etc.
2. Tables – In the Relational model the, relations are saved in the table format. It is stored along
with its entities. A table has two properties rows and columns. Rows represent records and
columns represent attributes.
3. Tuple – It is nothing but a single row of a table, which contains a single record.
4. Relation Schema: A relation schema represents the name of the relation with its attributes.
5. Degree: The total number of attributes which in the relation is called the degree of the relation.
6. Cardinality: Total number of rows present in the Table.
7. Column: The column represents the set of values for a specific attribute.
8. Relation instance – Relation instance is a finite set of tuples in the RDBMS system. Relation
instances never have duplicate tuples.
9. Relation key – Every row has one, two or multiple attributes, which is called relation key.
10. Attribute domain – Every attribute has some pre-defined value and scope which is known as
attribute domain
Relational Integrity Constraints
Relational Integrity constraints in DBMS are referred to conditions which must be present for a valid relation.

There are many types of Integrity Constraints in DBMS.


Constraints on the Relational database management system is mostly divided into three main categories are:
1.Domain Constraints
2.Key Constraints
3.Referential Integrity Constraints

Domain Constraints
Domain constraints can be violated if an attribute value is not appearing in the corresponding domain or it is not of the
appropriate data type.
Domain constraints specify that within each tuple, and the value of each attribute must be unique.

This is specified as data types which include standard data types integers, real numbers, characters, Booleans, variable
length strings, etc.
Example:
Create DOMAIN CustomerName CHECK (value not NULL)
● Key Constraints
● An attribute that can uniquely identify a tuple in a relation is called the key of the table. The
value of the attribute for different tuples in the relation has to be unique.
● Example:
● In the given table, CustomerID is a key attribute of Customer Table. It is most likely to have a
single key for one customer, CustomerID =1 is only for the CustomerName =” Google”.

CustomerID CustomerName Status


1 Google Active
2 Amazon Active
3 Apple Inactive
● Referential Integrity Constraints
● Referential Integrity constraints in DBMS are based on the concept of Foreign Keys. A foreign
key is an important attribute of a relation which should be referred to in other relationships.
Referential integrity constraint state happens where relation refers to a key attribute of a
different or same relation. However, that key element must exist in the table.

● In the above example, we have 2 relations, Customer and Billing.


● Tuple for CustomerID =1 is referenced twice in the relation Billing. So we know
CustomerName=Google has billing amount $300
Advantages of Relational Database Model
• Simplicity: A Relational data model in DBMS is simpler than the hierarchical and network model.
• Structural Independence: The relational database is only concerned with data and not with a structure.
This can improve the performance of the model.
• Easy to use: The Relational model in DBMS is easy as tables consisting of rows and columns are quite
natural and simple to understand
• Query capability: It makes possible for a high-level query language like SQL to avoid complex database
navigation.
• Data independence: The Structure of Relational database can be changed without having to change any
application.
• Scalable: Regarding a number of records, or rows, and the number of fields, a database should be enlarged
to enhance its usability.
Disadvantages of Relational Model
• Few relational databases have limits on field lengths which can’t be exceeded.
• Relational databases can sometimes become complex as the amount of data grows, and the relations
between pieces of data become more complicated.
• Complex relational database systems may lead to isolated databases where the information cannot be
shared from one system to another.
Database Schema
● A database schema is the logical representation of a database, which shows how the data is stored logically in the entire
database. It contains list of attributes and instruction that informs the database engine that how the data is organized and how
the elements are related to each other.
● A database schema contains schema objects that may include tables, fields, packages, views, relationships, primary key,
foreign key,
● In actual, the data is physically stored in files that may be in unstructured form, but to retrieve it and use it, we need to put it in
a structured form. To do this, a database schema is used. It provides knowledge about how the data is organized in a database
and how it is associated with other data.
● The schema does not physically contain the data itself; instead, it gives information about the shape of data and how it
can be related to other tables or models.
● A database schema object includes the following:
○ Consistent formatting for all data entries.
○ Database objects and unique keys for all data entries.
○ Tables with multiple columns, and each column contains its name and datatype.

● The complexity & the size of the schema vary as per the size of the project. It helps developers to easily manage and structure
the database before coding it.
Types of Database Schema
The database schema is divided into three types, which are:
● Logical Schema
● Physical Schema
● View Schema

1. Physical Database Schema


A physical database schema specifies how the data is stored physically on a storage system or disk storage in
the form of Files and Indices. Designing a database at the physical level is called a physical schema.
2. Logical Database Schema
● The Logical database schema specifies all the logical constraints that need to be applied to
the stored data. It defines the views, integrity constraints, and table. Here the term integrity
constraints define the set of rules that are used by DBMS (Database Management
System) to maintain the quality for insertion & update the data. The logical schema
represents how the data is stored in the form of tables and how the attributes of a table are
linked together.
● At this level, programmers and administrators work, and the implementation of the data
structure is hidden at this level.
● Various tools are used to create a logical database schema, and these tools demonstrate the
relationships between the component of your data; this process is called ER modelling.
● The ER modelling stands for entity-relationship modelling, which specifies the relationships
between different entities.
● We can understand it with an example of a basic commerce application. Below is the schema
diagram, the simple ER model representing the logical flow of transaction in a commerce
application.
● In the given example, the Ids are given in each circle, and these Ids are primary key &
foreign keys.
● The primary key is used to uniquely identify the entry in a document or record. The Ids of
the upper three circles are the primary keys.
● The Foreign key is used as the primary key for other tables. The FK represent the foreign
key in the diagram. It relates one table to another table.
3. View Schema
● The view level design of a database is known as view schema. This schema generally
describes the end-user interaction with the database systems.
Difference between the Physical and Logical Database
Schema
Physical database schema Logical Database schema

It does not include the attributes. It includes the attributes.


It contains both primary & secondary It also contains both primary & secondary
Keys. keys.

It contains the table name. It contains the names of the tables.


It contains the column names and their It does not contain any column name or
data types. datatype.
Keys
Keys play an important role in the relational database. It is used to uniquely identify any record or
row of data from the table. It is also used to establish and identify relationships between tables.

● Uniqueness: Keys ensure that each record in a table is unique, preventing duplicate entries.
● Integrity: They maintain the integrity of the database by establishing and enforcing
relationships between tables.
● Efficiency: Keys help in efficiently retrieving and updating records from the database.
● Referential Integrity: Foreign keys ensure that relationships between tables remain consistent
and that references between tables are valid.
Types of Keys in Database
● Management
Super Key - The set of attributes System
which can uniquely identify a tuple is known as Super Key. For
Example, STUD_NO, (STUD_NO, STUD_NAME) etc.
● Candidate Key - The minimal set of attribute which can uniquely identify a tuple is known as
candidate key. For Example, STUD_NO in STUDENT relation.
● Primary Key - There can be more than one candidate key in relation out of which one can be
chosen as the primary key. For Example, STUD_NO, as well as STUD_PHONE both, are
candidate keys for relation STUDENT but STUD_NO can be chosen as the primary key (only one
out of many candidate keys).
● Alternate Key - The candidate key other than the primary key is called an alternate key. For
Example, STUD_NO, as well as STUD_PHONE both, are candidate keys for relation STUDENT
but STUD_PHONE will be alternate key (only one out of many candidate keys).
● Foreign Key - is a column that creates a relationship between two tables. The purpose of Foreign
keys is to maintain data integrity and allow navigation between two different instances of an
entity.
● Composite key – Whenever a primary key consists of more than one attribute, it is known as a
composite key. This key is also known as Concatenated Key.
Candidate Key Example
 Lets select the candidate keys from the above set of super
● Lets take an example of table “Employee”. This table
keys.
has three attributes: Emp_Id, Emp_Number &
Emp_Name.
 1. {Emp_Id} – No redundant attributes
● Here Emp_Id & Emp_Number will be having unique  2. {Emp_Number} – No redundant attributes
values and Emp_Name can have duplicate values as  3. {Emp_Id, Emp_Number} – Redundant attribute. Either
more than one employees can have same name. of those attributes can be a minimal super key as both of
these columns have unique values.
● Emp_Id Emp_Number Emp_Name  4. {Emp_Id, Emp_Name} – Redundant attribute
● ------ ---------- -------- Emp_Name.
● E01 2264 Steve  5. {Emp_Id, Emp_Number, Emp_Name} – Redundant
● E22 2278 Ajeet attributes. Emp_Id or Emp_Number alone are sufficient
● E23 2288 Chaitanya enough to uniquely identify a row of Employee table.
● E45 2290 Robert  6. {Emp_Number, Emp_Name} – Redundant attribute
● How many super keys the above table can have? Emp_Name.
● 1. {Emp_Id}
● 2. {Emp_Number}
● 3. {Emp_Id, Emp_Number}  The candidate keys we have selected are:
● 4. {Emp_Id, Emp_Name}  {Emp_Id}
● 5. {Emp_Id, Emp_Number, Emp_Name}  {Emp_Number}
● 6. {Emp_Number, Emp_Name}
 Note: A primary key is selected from the set of candidate
keys. That means we can either have Emp_Id or
Emp_Number as primary key. The decision is made by
DBA (Database administrator)
Difference between Super Key and Candidate Key:

S.NO SUPER KEY CANDIDATE KEY

Super Key is an attribute (or set of attributes) that


1. is used to uniquely identifies all attributes in a Candidate Key is a proper subset of a super key.
relation.

2. All super keys can’t be candidate keys. But all candidate keys are super keys.

Various super keys together makes the criteria to Various candidate keys together makes the criteria to select the
3.
select the candidate keys. primary keys.

In a relation, number of super keys are more than While in a relation, number of candidate keys are less than
4.
number of candidate keys. number of super keys.

5. Super key’s attributes can contain NULL values. Candidate key’s attributes can also contain NULL values.
END of UNIT I

You might also like