DBMS_UNIT-1
DBMS_UNIT-1
proceeding:
This document is confidential and intended solely for the educational purpose
of RMK Group of Educational Institutions. If you have received this document
through email in error, please notify the system manager. This document
contains proprietary information and is intended only to the respective group /
learning community as intended. If you are not the addressee you should not
disseminate, distribute or copy through e-mail. Please notify the sender
immediately by e-mail if you have received this document by mistake and
delete this document from your system. If you are not the intended recipient
you are notified that disclosing, copying, distributing or taking any action in
reliance on the contents of this information is strictly prohibited.
20CB402
Database
Management
Systems
Department: Computer Science and Business
Systems
Batch/Year: 2021-2025 / II Year
Created by:
Ms. Indhumathi C
Edited by:
Date:
18.01.2023
Table of Contents
2. Course Objectives 6
6. CO-PO/PSO Mapping 10
Understand the basic concepts of Database, why its required and what its benefits
& advantage
How to efficiently model and design various database objects and entities
UNIT I INTRODUCTION 9
Relational query languages: Relational algebra, Tuple and domain relational calculus,
SQL3, DDL and DML constructs, Open source and Commercial DBMS - MYSQL, ORACLE,
DB2, SQL server. Relational database design: Domain and data dependency,
Armstrong's axioms, Functional Dependencies, Normal forms, Dependency preservation,
Lossless design.
Database Security: Authentication, Authorization and access control, DAC, MAC and
RBAC models, Intrusion detection, SQL injection. Object oriented and object relational
databases, Logical databases, Web databases, Distributed databases, Data warehousing
and data mining.
Course Outcomes
CO1: Able to design and deploy an efficient & scalable data storage node for
varied kind of application requirements
POs/PSOs
COs
PSO3
PO6
PO7
PO1
PO2
PO3
PO4
PO5
PO8
PO9
PSO
PSO
PO1
PO1
PO1
2
1
0
2
CO1 3 3 3 - 1 - - - 2 - - 3 2 2 2
CO2 3 3 3 3 1 - - - - - - 3 2 2 3
CO3 3 3 3 3 2 - - - - - - 3 2 2 3
CO4 3 3 3 3 3 - - - - - - 3 2 2 3
CO5 3 3 3 3 2 - - - - - - 3 2 2 3
Unit I
Introduction
Lecture Plan
UNIT - I
Actual Date
S. Scheduled Mode of Taxonom
Topic of CO
No. Date Delivery y Level
Completion
Crossword Puzzle:
Left to Right:
8. The process of compiling and breaking the components of stored procedure into various parts(7)
9. Replaces NULL with the specified replacement value(6)
Right to Left:
10. Combines the results of two or more queries into a single result as a distinct output(5)
11. A statement evaluates a list of conditions and returns one of the various possible results(4)
12. A keyword matches the given character string with the specified pattern(4)
13. A virtual table that provides access to a subset of columns from one or more tables(4)
Bottom to Top:
Databases and database technology have had a major impact on the growing use
of computers. It is fair to say that databases play a critical role in almost all areas
where computers are used, including business, electronic commerce, social
media, engineering, medicine, genetics, law, education, and library science.
The term data can be defined as a set of isolated and unrelated raw facts with an
implicit meaning. Data can be anything such as, name of a person, a number,
images, sound, etc. For example, ‗Monica,‗ ‗25,‗ ‗student,‗ etc., is a data. When
the data is processed and converted into a meaningful and useful form, it is
known as information.
Database:
A database can be defined as a collection of related data from which users can
efficiently retrieve the desired information.
A database is designed, built, and populated with data for a specific purpose.
It has an intended group of users and some preconceived applications in
which these users are interested.
Purpose of Database:
In the early days, database applications were built directly on top of file systems.
For example, consider a savings-bank enterprise that keeps information about all
customers and savings accounts in files. The users can manipulate the
information in the files using application programs. Some of the programs are,
A program to debit or credit an account
System programmers wrote these applications to meet the needs of the bank.
New application programs are written as the need arises. For example, if the
savings bank decides to offer checking accounts, the bank creates new
permanent files that contain information about all the checking accounts, and
system programmers has to write new application programs to deal with
situations that do not arise in savings accounts, such as overdrafts. Thus as time
goes by, the system requires more files and more application programs . This
leads to several disadvantages as given below:
Since different programmers create the files and application programs, the files
will have a different format and the programs may be written in several
programming languages. Also the same information may be duplicated in several
files. For example the address and telephone number of a particular customer
may appear in a file that consists of saving-account records and in a file that
consist of checking account records. This redundancy leads to higher storage
and access cost.
Data inconsistency occurs, if the various copies of the same data may no longer
agree. For example, a changed customer address may be reflected in savings
account records but not elsewhere in the system.
Suppose that a bank officer needs to find the names of all customers who live in a
particular postal-code area. The officer insists the data processing department to
generate such a list. The original system has no application program to meet the
request. However, the system has an application program to generate the list of
all customers. The officer has only two choices: either can obtain the list of all
customers and extract the needed information manually or ask the system
programmer to write the necessary application program. Both are unsatisfactory.
3) Data isolation
Because data are scattered in various files, and files may be in different formats,
writing new application programs to retrieve the appropriate data is difficult.
4) Integrity problems
The data values stored in a database must satisfy some consistency constraints.
For example, the balance of a bank account may never fall below a prescribed
amount (say, $50). Developers enforce these constraints in the system by adding
appropriate code in the various application programs. However, when new
constraints are added it is difficult to change the programs to enforce them.
5) Atomicity Problems
To improve the overall performance of the system, many systems allow multiple
users to update the data simultaneously. In such an environment, interaction of
concurrent updates may result in inconsistent data. For example consider bank
account A, containing $500. If two customers withdraw funds (say $50 and $100
respectively) from account at about the same time, the result of the concurrent
executions may leave the account in an incorrect state. If the two programs run
concurrently, they may both read the value $500, and write the result back $450
and $400 respectively. Depending on which one writes the value last, the account
may contain either $450 or $400, rather than the correct value of $350.
7) Security Problems
Every user of the database system should not be able to access all the data. For
example, in a banking system, payroll personnel need to see only that part of the
database that has information about the various bank employees. They do not
need to access information about customer accounts. The file processing systems
do not enforce security constraints
Areas of Database Applications:
Object-oriented DBMSs
Constructing the database is the process of storing the data on some storage
medium that is controlled by the DBMS.
Sharing a database allows multiple users and programs to access the database
simultaneously.
A query typically causes some data to be retrieved; a transaction may cause some
data to be read and some data to be written into the database.
Other important functions provided by the DBMS include
• This definition is stored in the DBMS catalog, which contains information such as
the structure of each file, the type and storage format of each data item, and
various constraints on the data.
• The information stored in the catalog is called meta-data, and it describes the
• The catalog is used by the DBMS software and also by database users who need
information about the database structure. A general-purpose DBMS software
package is not written for a specific database application. Therefore, it must refer
to the catalog to know the structure of the files in a specific database, such as the
type and format of data it will access.
program-data independence
• DBMS access programs do not require such changes in most cases. The
structure of data files is stored in the DBMS catalog separately from the
access programs. We call this property program-data independence
program-operation independence
• The interface (or signature) of an operation includes the operation name and
the data types of its arguments (or parameters).
Data Abstraction
not include many of the details of how the data is stored or how the
operations are implemented.
• A database typically has many types of users, each of whom may require a
different perspective or view of the database.
• A view may be a subset of the database or it may contain virtual data that is
• Some users may not need to be aware of whether the data they refer to is
stored or derived.
• A multiuser DBMS, as its name implies, must allow multiple users to access the
database at the same time.
• The DBMS must include concurrency control software to ensure that several
users trying to update the same data do so in a controlled manner so that the
result of the updates is correct.
• For example, when several reservation agents try to assign a seat on an airline
flight, the DBMS should ensure that each seat can be accessed by only one
agent at a time for assignment to a passenger.
The different types of people who work in a database system environment are
The people whose jobs involve the day-to-day use of a large database; we
call them the actors on the scene
People who may be called workers behind the scene – those who work
to maintain the database system environment but who are not actively interested in
the database contents as part of their daily job.
.
Database Administrators
• In a database environment, the primary resource is the database itself, and the
secondary resource is the DBMS and related software. Administering these resources is
the responsibility of the database administrator (DBA).
• The DBA is responsible for authorizing access to the database, coordinating and
monitoring its use, and acquiring software and hardware resources as needed.
• The DBA is accountable for problems such as security breaches and poor system
response time.
Database Designers
• In many cases, the designers are on the staff of the DBA and may be
assigned other staff responsibilities after the database design is completed.
• Database designers typically interact with each potential group of users and
develop views of the database that meet the data and processing
requirements of these groups.
• Each view is then analyzed and integrated with the views of other user
groups. The final database design must be capable of supporting the
requirements of all user groups.
End users
• Are the people whose jobs require access to the database for querying, updating,
and generating reports; the database primarily exists for their use.
• Occasionally access the database, but they may need different information each
time.
• They use a sophisticated database query interface to specify their requests and
• Their main job function revolves around constantly querying and updating the
• Examples: Bank customers and tellers check account balances and post
withdrawals and deposits.
• Reservation agents or customers for airlines, hotels, and car rental companies
check availability for a given request and make reservations.
familiarize themselves with the facilities of the DBMS in order to implement their
own applications to meet their complex requirements.
Standalone users
System analysts determine the requirements of end users, especially naive and
parametric end users, and develop specifications for standard canned transactions
that meet these requirements.
These persons are typically not interested in the database content itself. We call
them the workers behind the scene, and they include the following categories:
Design and implement the DBMS modules and interfaces as a software package.
The DBMS must interface with other system software, such as the operating system
and compilers for various programming languages.
Tool developers
• In many cases, independent software vendors develop and market these tools.
Controlling Redundancy
This redundancy in storing the same data multiple times leads to several
problems.
• First, there is the need to perform a single logical update such as entering data on
a new student multiple times: once for each file where student data is recorded.
This leads to duplication of effort.
• Second, storage space is wasted when the same data is stored repeatedly, and
• Third, files that represent the same data may become inconsistent.
• When multiple users share a large database, it is likely that most users will not be
authorized to access all information in the database. For example, financial data
such as salaries and bonuses is often considered confidential, and only authorized
persons are allowed to access such data.
• In addition, some users may only be permitted to retrieve data, whereas others
are allowed to retrieve and update. Hence, the type of access operation—retrieval
or update—must also be controlled. Typically, users or user groups are given
account numbers protected by passwords, which they can use to gain access to
the database.
• A DBMS should provide a security and authorization subsystem, which the DBA
uses to create accounts and to specify account restrictions.
Databases can be used to provide persistent storage for program objects and data
structures.
Database systems must provide capabilities for efficiently executing queries and
updates.
The DBMS must provide specialized data structures and search techniques to speed
up disk search for the desired records.
Auxiliary files called indexes are often used for this purpose.
Indexes are typically based on tree data structures or hash data structures that are
suitably modified for disk search.
Therefore, the DBMS often has a buffering or caching module that maintains
parts of the database in main memory buffers.
The query processing and optimization module of the DBMS is responsible for
choosing an efficient query execution plan for each query based on the existing
storage
A DBMS must provide facilities for recovering from hardware or software failures.
The backup and recovery subsystem of the DBMS is responsible for recovery.
structures.
Providing Multiple User Interfaces
• Because many types of users with varying levels of technical knowledge use a
• These include apps for mobile users, query languages for casual users,
programming language interfaces for application programmers, forms and
command codes for parametric users, and menu-driven interfaces and natural
language interfaces for standalone users. Both forms-style interfaces and menu-
driven interfaces are commonly known as graphical user interfaces (GUIs).
• A database may include numerous varieties of data that are interrelated in many
ways
• Most database applications have certain integrity constraints that must hold for
the data.
• A DBMS should provide capabilities for defining and enforcing these constraints.
• The simplest type of integrity constraint involves specifying a data type for each
data item.
• Rules that pertain to a specific data model are called inherent rules of the data
model.
• A more complex type of constraint that frequently occurs involves specifying that
a record in one file must be related to records in other files. For example, in
Figure 1.2, we can specify that every section record must be related to a course
record. This is known as a referential integrity constraint.
• Some database systems provide capabilities for defining deduction rules for
inferencing new information from the stored database facts. Such systems are
called deductive database systems
• The database approach permits the DBA to define and enforce standards among
database users in a large organization.
change.
• For example, a new user group may emerge that needs information not currently
in the database. In response, it may be necessary to add a file to the database or
to extend the data elements in an existing file
• A DBMS makes the database available to all users. As soon as one user‘s update
is applied to the database, all other users can immediately see this update.
Economies of Scale.
The DBMS approach permits consolidation of data and applications, thus reducing
the amount of wasteful overlap between activities of data-processing personnel in
different projects or departments as well as redundancies among applications.
Applications of DBMS
Scientific applications that store large amounts of data resulting from scientific
experiments in areas such as high-energy physics, the mapping of the human
genome, and the discovery of protein structures ■
Data mining applications that analyze large amounts of data to search for the
occurrences of specific patterns or relationships, and for identifying unusual patterns
in areas such as credit card fraud detection
Spatial applications that store and analyze spatial locations of data, such as
weather information, maps used in geographical information systems, and
automobile navigational systems
Time series applications that store information such as economic data at regular
points in time, such as daily sales and monthly gross national product figures.
A Data Model
The principles of the relational model were first outlined by Dr. E.F. Codd. The
Relational Data model represents a database as a collection of tables, where each
table can be stored as a separate file.
Most relational databases have high-level query languages and support a limited
form of user views. RDBMS relational database management system is based on
the relational model developed by E.F. Codd.
A set records
A set links
The record types are made up of fields in the usual way. Links may be followed in
their direction.
Hierarchical Model
This structure implies that a record can have repeating information, generally in
the child data segments. Data in a series of records, which have a set of field
values attached to it.
It collects all the instances of a specific record together as a record type. These
record types are the equivalent of tables in the relational model, and with the
individual records being the equivalent of rows.
To create links between these record types, the hierarchical model uses Parent
Child Relationships. These are a 1:N mapping between record types.
For example, an organization might store information about an employee, such as
name, employee number, department, salary. The organization might also store
information about an employee‘s children, such as name and data of birth.
The employee and children data forms a hierarchy, where the employee data
represents the parent segment and the children data represents the child
segment.
If an employee has three children, then there would be three child segments
associated with one employee segment.
The first database systems developed were hierarchical. Hierarchical DBMSs were
popular from the late 1960s, with the introduction of IBM‘s Information
Management System (IMS) DBMS, through the 1970s.
2. Segment types are linked in a parent/child hierarchical where each child segment
type has
Disadvantages
Object-Oriented Database
Some object database can be used in multiple languages. For example, Gemstone
database supports C++, Smalltalk and Java programming languages.
RDBMS have SQL as a standard query language. Object databases do not have a
standard.
Encapsulation,
Methods Or
Functions And
Object Identity
A database system is partitioned into modules that deal with each of the
responsibilities of the overall system.
The functional components of a database system can be broadly divided into the
storage manager and the query processor components
Naive users: unsophisticated users who interact with the system by invoking one
of the application programs that have been written previously.
Sophisticated users: interact with the system without writing programs using a
database query language or by using tools such as data analysis software.
Specialized users: write specialized database applications that do not fit into the
traditional data-processing framework. For example, CAD, graphic data, audio,
video.
Database Administrator: A person who has central control over the system is
called a database administrator DBA, whose functions are:
Schema definition
Ensuring that enough free disk space is available for normal operations, and
upgrading disk space as required
Monitoring jobs running on the database and ensuring that performance is not
degraded by very expensive tasks submitted by some users
Query Processor
The query processor is important because it helps the database system to simplify
and facilitate access to data.
DDL interpreter: interprets DDL statements and records the definitions in the
data dictionary.
Storage Manager
The storage manager is the component of a database system that provides the
interface between the low-level data stored in the database and the application
programs and queries submitted to the system.
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.
File manager
Buffer manager
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.
The buffer manager is a critical part of the database system, since it enables the
database to handle data sizes that are much larger than the size of main memory.
Indices: can provide fast access to data items. A database index provides
pointers to those data items that hold a particular value.
Database Languages
Data-Manipulation Language
Procedural DMLs require a user to specify what data are needed and how to
get those data.
Declarative DMLs are usually easier to learn and use than are procedural DMLs.
However, since a user does not have to specify how to get the data, the database
system has to figure out an efficient means of accessing data.
We specify the storage structure and access methods used by the database
system by a set of statements in a special type of DDL called a data storage
and definition language. These statements define the implementation details of
the database schemas, which are usually hidden from the users.
The data values stored in the database must satisfy certain consistency
constraints.
For example, suppose the university requires that the account balance of a
department must never be negative.
The DDL provides facilities to specify such constraints. The database system
checks these constraints every time the database is updated. In general, a
constraint can be an arbitrary predicate pertaining to the database.
Assertions. An assertion is any condition that the database must always satisfy.
Domain constraints and referential-integrity constraints are special forms of
assertions. However, there are many constraints that we cannot express by using
only these special forms. For example, ―Every department must have at least five
courses offered every semester‖ must be expressed as an assertion.
When an assertion is created, the system tests it for validity. If the assertion is
valid, then any future modification to the database is allowed only if it does not
cause that assertion to be violated.
Authorization. We may want to differentiate among the users as far as the type
of access they are permitted on various data values in the database. These
differentiations are expressed in terms of authorization, the most common
being: read authorization, which allows reading, but not modification, of data;
insert authorization, which allows insertion of new data, but not modification of
existing data; update authorization, which allows modification, but not
deletion, of data; and delete authorization, which allows deletion of data. We
may assign the user all, none, or a combination of these types of authorization.
The DDL, just like any other programming language, gets as input some
instructions (statements) and generates some output. The output of the DDL is
placed in the data dictionary, which contains metadata—that is, data about
data. The data dictionary is considered to be a special type of table that can only
be accessed and updated by the database system itself (not a regular user). The
database system consults the data dictionary before reading or modifying actual
data.
INTRODUCTION TO ER MODEL
• Entity-Relationship (ER) model is a diagrammatic representation of logical
structure of database.
• The ER model describes data as entities, relationships, and attributes.
Entity
• An entity is an object that exists and is distinguishable from other objects.
• An entity may be an object with a physical existence or conceptual existence
Example:
Physical existence: a particular person, car, house, or employee
Conceptual existence: a company, a job, or a university course
Entity type:
• An entity type defines a collection (or set) of entities that have the same
attributes.
Entity set:
• The collection of all entities of a particular entity type in the database is called an
entity set.
Attributes:
• Each entity has attributes—the particular properties that describe it.
• Example, an EMPLOYEE entity may be described by the employee‘s name, age,
address, salary, and job.
• A particular entity will have a value for each of its attributes.
Value Sets (Domains) of Attributes:
• Specifies the set of values that may be assigned to that attribute for each
individual entity.
• Value set for the Name attribute to be the set of strings of alphabetic characters
separated by blank characters.
Types of attributes
Simple Attribute:
• Attributes that are not divisible are called simple or atomic attributes.
Composite attribute:
• Attributes having a single value for a particular entity are called single-valued
attributes
Multivalued Attributes:
• Attributes that have a set of values for the same entity are called as multivalued
attributes
• A multivalued attribute may have lower and upper bounds to constrain the
number of values allowed for each individual entity.
• The Age attribute is hence called a derived attribute and is said to be derivable
from the Birthdate attribute, which is called a stored attribute.
Null values:
• An attribute takes null value when an entity does not have a value for it.
• Example:
44553 (Peltier) advisor 22222 (Einstein)
student entity relationship set instructor entity
Participation:
• Role : The function that an entity plays in a relationship is called as role. Roles
are implicit, and or not specified. If same entity set participates more than once
in a relationship type in different roles, role name becomes essential.
• Example: the advisor relationship set between entity sets instructor and student
may have the attribute date which tracks when the student started being
associated with the advisor.
• A relationship set of degree two is called binary, and one of degree three is called
ternary
Constraints:
1. Mapping cardinalities
2. Key constraints
3. Participation constraints
Mapping cardinalities:
• Express the number of entities to which another entity can be associated via a
relationship set.
• For a binary relationship set the mapping cardinality must be one of the following types:
1. One to one
2. One to many
3. Many to one
4. Many to many
Participation Constraints:
• An entity set that does not have a primary key is referred to as a weak entity set.
• It must relate to the identifying entity set via a total, one-to-many relationship set
from the identifying to the weak entity set
Specialization:
• Attribute inheritance – a lower-level entity set inherits all the attributes and
• A bottom-up design process – combine a number of entity sets that share the
• Specialization and generalization are simple inversions of each other; they are
Aggregation:
https://www.youtube.com/watch?v=wOD02sezmX8
ER Diagram for University Database
Reducing ER to Relational Model
• For each regular (strong) entity type E in the ER schema, create a relation R that includes
all the simple attributes of E.
• If the chosen key of E is composite, the set of simple attributes that form it will together
form the primary key of R.
• For each weak entity type W in the ER schema with owner entity type E, create a relation
R & include all simple attributes (or simple components of composite attributes) of W as
attributes of R.
• Also, include as foreign key attributes of R the primary key attribute(s) of the relation(s)
that correspond to the owner entity type(s).
• The primary key of R is the combination of the primary key(s) of the owner(s) and the
partial key of the weak entity type W, if any.
Step 3: Mapping of Binary 1:1 Relation Types
• For each binary 1:1 relationship type R in the ER schema, identify the relations S and T
that correspond to the entity types participating in R.
1. Foreign Key approach: Choose one of the relations-say S-and include a foreign key in
S the primary key of T. It is better to choose an entity type with total participation in R
in the role of S.
• For each regular binary 1:N relationship type R, identify the relation S that represent the
participating entity type at the N-side of the relationship type.
• Include as foreign key in S the primary key of the relation T that represents the other
entity type participating in R.
• For each regular binary M:N relationship type R, create a new relation S to represent R.
• Include as foreign key attributes in S the primary keys of the relations that represent the
participating entity types; their combination will form the primary key of S.
• Also include any simple attributes of the M:N relationship type (or simple components of
composite attributes) as attributes of S.
Step 6: Mapping of Multivalued attributes.
• For each multivalued attribute A, create a new relation R.
• This relation R will include an attribute corresponding to A, plus the primary key
attribute K-as a foreign key in R-of the relation that represents the entity type of
relationship type that has A as an attribute.
• The primary key of R is the combination of A and K. If the multivalued attribute is
composite, we include its simple components.
Step 7: Mapping of N-ary Relationship Types.
• For each n-ary relationship type R, where n>2, create a new relationship S to
represent R.
• Include as foreign key attributes in S the primary keys of the relations that
represent the participating entity types.
• Also include any simple attributes of the n-ary relationship type (or simple
components of composite attributes) as attributes of S.
Step8: Options for Mapping Specialization or Generalization.
• Convert each specialization with m subclasses {S1, S2,….,Sm} and generalized
superclass C, where the attributes of C are {k,a1,…an} and k is the (primary) key,
into relational schemas using one of the four following options:
Option 8A: Multiple relations-Superclass and subclasses
Option 8B: Multiple relations-Subclass relations only
Option 8C: Single relation with one type attribute
Option 8D: Single relation with multiple type attributes
Step 9: Mapping of Union Types (Categories).
• For mapping a category whose defining superclass have different keys, it is
customary to specify a new key attribute, called a surrogate key, when creating a
relation to correspond to the category.
Derived Relational Schema for ER Diagram on
University
SQL Fundamentals:
Data-definition Language (DDL): the SQL DDL provides commands for defining
relation schemas, deleting relations, and modifying relation schemas.
The SQL standard supports a variety of built-in domain types such as,
date: A calendar date containing a (four digit) year, month and day of the month.
.
Data definition Language:
The SQL data definition language allows specification of not only a set of relations
but also information about each relation, including
• Integrity constraints
DDL Commands:
Syntax:
where,
r is the name of the relation
each Ai is an attribute name in the schema of relation r
Di is the data type of values in the domain of attribute Ai
Primary key : The primary key specification says that attributes are required to be
non-null and unique. That is no tuple can have a null value for a primary key
attribute, and also there should not be duplicate values.
Check (P) : the check clause specifies a predicate P that must be satisfied by every
tuple in the relation.
Unique : it will not allow duplicate values and null values. The difference between
the primary key and the unique key is that there can be more than unique key
attribute.
Example:
Referential Integrity:
We may not add record to the child table unless the foreign key for that record
points to an existing record in the parent table.
If a record in the parent table is deleted all corresponding records in the child table
must be deleted using a cascading delete.
If the primary key for a record in the parent table changes, all corresponding
records in the child table must be modified using cascading update.
Syntax:
Parent table:
Child table:
Alter table:
Alter table command is used to add, modify or drop attributes or columns from
the table.
Syntax:
Example:
Truncate table:
The truncate table command deletes the rows in the table but retains the table
structure.
Syntax:
Example:
Syntax:
Example:
It includes also commands to insert tuples into, delete tuples from, and modify
tuples in the database.
DML Commands:
The basic structure of an SQL expression consists of three clauses: select, from,
and where.
The select clause list the attributes desired in the result of a query. It corresponds
to the projection operation of the relational algebra
Elimination of Duplicates:
Sql query:
Without Duplication:
SQL uses the keyword all to specify explicitly that duplicates are not removed.
Sql query:
Sql query:
Arithmetic operators:
The select clause may also contain arithmetic expressions involving the operators
+,-,*, and / operating on constants or attributes of tuples.
Sql Query:
will return a relation that is same as the loan relation, except that the attribute
amount is multiplied by 100.
Example: Find all loan numbers for loans made at the perryridge branch with loan
numbers greater then $1200.
Sql query:
SQL uses the logical connectives and, or, and not rather than mathematical
symbols in the where clause.
Between Operator:
Example: Find the loan number of those loans with loan amounts between $90,000
and $100,000.
Sql Query:
select loan-number from loan where amount between 90000 and 100000
2) Deletion:
A delete request is expressed in much the same way as a query. Sql expresses a
deletion by
delete command operates on only one relation. To delete values from several
relations delete command should be used for each relation separately.
The delete request can contain a nested select that references the relation from
which tuples are to be deleted. For example, to delete the records of all accounts
with balances below the average at the bank, the following query is used.
delete from account where balance< ( select avg (balance) from account);
The above query first tests each tuple in the relation account to check whether
the account has a balance less than the average at the bank. Then, all tuples that
fail the test are deleted.
3) Insertion:
To insert data into a relation, the attribute values of inserted tuples must be the
members of the attribute‘s domain. Similarly, tuples inserted must be of the
correct type.
Example1:
Example 2:
Example 3:
Inserts tuples into account relation which is taken from loan relation.
Example 4:
Insert into depositor select customer-name, loan-no from borrower, loan where
borrower.loan-no = loan.loan-no and branch-name = ‗Perryridge‘;
Selects the tuples from borrower and loan relations whose loan numbers are
equal, also whose branch is perryridge and inserts those tuples into the relation
depositor.
Example 5:
4)Updates:
Update statement is used to change the values of the tuples without affecting
other tuples in the relation.
Example 1:
Example 2:
updates the balance as specified in the condition where balance is greater than or
equal to1000.
Example 3:
Sql provides a case construct, which performs two updates with a single update
statement.
update account set balance = case when balance <= 10000 then balance *
1.05 else balance * 1.06 end;
Integrity Constraints
Integrity constraints ensure that the data insertion, updating, and other processes
have to be performed in such a way that data integrity is not affected.
1. Domain constraints
Domain constraints can be defined as the definition of a valid set of values for an
attribute.
The data type of domain includes string, character, integer, time, date, currency,
etc. The value of the attribute must be available in the corresponding domain.
Example:
2..Entity integrity constraints
The entity integrity constraint states that primary key value can't be null.
This is because the primary key value is used to identify individual rows in relation
and if the primary key has a null value, then we can't identify those rows.
A table can contain a null value other than the primary key field.
Example:
4. Key constraints
Keys are the entity set that is used to identify an entity within its entity set
uniquely.
An entity set can have multiple keys, but out of which one key will be the primary
key. A primary key can contain a unique and null value in the relational table.
Example:
ASSIGNMENTS
1. Consider the employee database.
Emp(ename,street,city)
Works(ename,companyname,salary)
Company(companyname,city)
Manages(ename,managername)
1. Find the names of all employees who work for First Bank Corporation.
2. Find the names, street address, and cities of residence of all employees
who work for first Bank Corporation and earn more than 200000 per annum.
4. Find the names of all employees in this database who live in the same city
as the companies for which they work.
5. Find the names of all employees who live in the same city and on the same
street as do their managers.
6. Find the names of all employees who earn more than every employees of
small bank corporation.
ASSIGNMENTS
2. Consider the following schema:
The key fields are underlined, and the domain of each field is listed after the field
name. Therefore sid is the key for Suppliers, pid is the key for Parts and sid and pid
together form the key for Catalog. The Catalog relation lists the prices charged for
parts by Suppliers. Write the following queries in relational algebra and SQL.
Find the sids of suppliers who supply some red or green part.
Find the sids of suppliers who supply every red part or supply every green part.
Emp(ename,street,city)
Works(ename,companyname,salary)
Company(companyname,city)
Manages(ename,managername)
Give the SQL DDL definition of this database. Identify referential integrity constraints
that should hold and include them in the DDL definition.
ASSIGNMENTS
4. Express in SQL Queries:
Consider relations:
River(name, origin,length)
Find all countries whose GDP is greater than $500 billion but less than $1 trillion.
List the life expectancy in countries that have river originating in them.
Find all cities that are either in South America or whose population is less than 2
million.
Display the list of all customers by Cust_No with the city in which each is located.
List the names of the sales persons who have accounts in Delhi.
11. Part A Question & Answer
Unit - 1 RELATIONAL DATABASES
2. Explain the difference between logical and physical data independence. (CO1 )(K1)
3. Compare the features of conventional database system system with database system.
(CO1 )(K2)
6. Explain the three different groups of data models with examples. (CO1 )(K2)
8. Explain in detail about Entity Relational Model with suitable examples. (CO1 )(K2)
9. Consider the employee database where the primary keys are underlined. (CO1 )(K4)
a. Emp(ename,street,city)
b. Works(ename,companyname,salary)
c. Company(companyname,city)
d. Manages(ename,managername)
Find the names of all employees who work for First Bank Corporation.
Find the names, street address, and cities of residence of all employees who work for first
Bank Corporation and earn more than 200000 per annum.
Find the names of all employees in this database who live in the same city as the
companies for which they work.
Find the names of all employees who earn more than every employees of small bank
corporation.
13. What are the major components used in ER diagram. Explain in detail(CO1 )(K2)
What Is MongoDB?
MongoDB is a document database with the scalability and flexibility that you want
with the querying and indexing that you need
Makes development easy
MongoDB‘s document model is simple for developers to learn and use, while still
providing all the capabilities needed to meet the most complex requirements at
any scale. We provide drivers for 10+ languages, and the community has built
dozens more.
MongoDB stores data in flexible, JSON-like documents, meaning fields can vary from
document to document and data structure can be changed over time
The document model maps to the objects in your application code, making data
easy to work with
Ad hoc queries, indexing, and real time aggregation provide powerful ways to access
and analyze your data
MongoDB is a distributed database at its core, so high availability, horizontal scaling,
and geographic distribution are built in and easy to use
MongoDB is free to use.
MongoDB Architecture
MongoDB is designed to meet the demands of modern apps with a technology
foundation that enables you through:
The document data model – presenting you the best way to work with data.
A distributed systems design – allowing you to intelligently put data where you
want it.
A unified experience that gives you the freedom to run anywhere – allowing you
to future-proof your work and eliminate vendor lock-in.
Assessment Schedule
Assessment I
Proposed Date : 28.2.2023
Actual Date :
Text Books & References
TEXT BOOKS:
1. Abraham Silberschatz, Henry F.Korth, S. System 6 th Edition, Tata McGraw Hill,2011.
2. Elmasri R. and S. Navathe, Database Systems: Models, Languages, Design and
Application Programming, Pearson Education, 2013.
REFERENCES:
1. Principles of Database and Knowledge – Base Systems, Vol 1 by J. D. Ullman.
2. Foundations of Databases. Serge Abiteboul, Richard Hull, Victor Vianu.
18. MINI PROJECT SUGGESTIONS
Hospitals have unique data requirements. They have to maintain the medical records of their
patients, and manage their staff and its multiple departments. You can solve the data-related
problems of hospitals by creating a DBMS solution.
First, you should assign unique IDs to the patients and store the relevant information under
the same. You‘ll have to add the patient‘s name, personal details, contact number, disease
name, and the treatment the patient is going through. You‘ll also have to mention under
which hospital department the patient is (such as cardiac, gastro, etc.).
A doctor can treat multiple patients, and he/she would have a unique ID as well. Doctors
would also be classified in different departments.
Patients would get admitted into rooms, so you‘ll need to add that information in your
database too. Then, you‘d have to add the information of ward boys and nurses working in
the hospital and assigned to different rooms.
You should start by adding donor names and assign them unique IDs. Add their details and
relevant information such as blood type, medical report, and contact number. Similarly, add
patient names with unique IDs, details on their medical conditions, and blood types.
After you‘ve created a database of patients and donors, you can work on a database for the
blood bank. There, you‘ll have to add the name of the blood bank, its staff details, operating
hours, and address.
18. MINI PROJECT SUGGESTIONS
4) Inventory Management
The project starts by adding a seller and by adding details of customer. the user can now
purchase new products by the desired seller and then can sell them to the customer, the
purchasing and selling of products is reflected in the inventory section. The main aim of
Inventory Management Mini DBMS project is to add new products and sell them and keep an
inventory to manage them.
Add features like providing the menu of the food items that are prepared in the hotel. Provide
the menu and prices of the food in the hotel. you can add the online food ordering facility to
this which will give a good impression on the project. we can also book the tables in the
project. Add a feature that will show the collection of the day this will be only viewed by the
admin. we can also provide online booking of rooms also. Improve this with some other
features.
Thank you
Disclaimer:
This document is confidential and intended solely for the educational purpose of RMK Group
of Educational Institutions. If you have received this document through email in error,
please notify the system manager. This document contains proprietary information and is
intended only to the respective group / learning community as intended. If you are not the
addressee you should not disseminate, distribute or copy through e-mail. Please notify the
sender immediately by e-mail if you have received this document by mistake and delete this
document from your system. If you are not the intended recipient you are notified that
disclosing, copying, distributing or taking any action in reliance on the contents of this
information is strictly prohibited.