VimalDBMS I, II Unit
VimalDBMS I, II Unit
Single Transaction: Alice withdraws USD 100 from her account and sends to Bob
• There are following four commonly known properties of a relational model known as ACID properties,
where:
• A means Atomicity: This ensures the data operation will complete either with success or with failure. It
follows the 'all or nothing' strategy. For example, a transaction will either be committed or will abort.
Atomic (single) transaction
As you withdrew the money from Alice’s account, the system crashes before you put it into Bob’s. You
would have a weird state, where Alice would be missing $100 from her account, but Bob would not have
received them.
• C means Consistency: Data updated via transactions to respect the other constraints or rules within the
database systems to keep data in a consistent state
Constraints that check personal balances and prevent an account from withdrawing more money than
they have. So if Alice started with $50, she would not be allowed to send 100 dollars to Bob.
Properties of Relational Database - 2
• I means Isolation: There can be concurrent users for accessing data at the same time
from the database. Thus, isolation between the data should remain isolated. For
example, when multiple transactions occur at the same time, one transaction effects
should not be visible to the other transactions in the database.
Two transactions for a $50 withdrawal start at the same time. The transactions run in
isolation which guarantees that when they both complete, we’ll have a balance of $0
instead of $50
.
• D means Durability: It ensures that once it completes the operation and commits the
data, data changes should remain permanent.
Transactions and database modifications are not kept in volatile memory but are
saved to permanent storage, such as disks. This prevents data loss during system
failure, such as a power outage.
NoSQL Database
• Non-SQL/Not Only SQL is a type of database that is used for storing a wide range of
data sets.
• It is not a relational database as it stores data not only in tabular form but in several
different ways.
• It came into existence when the demand for building modern applications increased.
• Thus, NoSQL presented a wide variety of database technologies in response to the
demands.
• We can further divide a NoSQL database into the following four types:
1. Key-value storage: It is the simplest type of database storage where it stores every single item
as a key (or attribute name) holding its value, together.
2. Document-oriented Database: A type of database used to store data as JSON-like document.
It helps developers in storing data by using the same document-model format as used in the
application code.
3. Graph Databases: It is used for storing vast amounts of data in a graph-like structure. Most
commonly, social networking websites use the graph database.
4. Wide-column stores: It is similar to the data represented in relational databases. Here, data is
stored in large columns together, instead of storing in rows.
Cloud Database
• A type of database where data is stored in a virtual
environment and executes over the cloud computing platform.
• It provides users with various cloud computing services
(SaaS, PaaS, IaaS, etc.) for accessing the database.
• There are numerous cloud platforms, but the best options are:
• Amazon Web Services(AWS)
• Microsoft Azure
• PhonixNAP
• ScienceSoft
• Google Cloud SQL, etc.
Object-oriented Databases
• The type of database that uses the object-based data model approach for storing data in the
database system.
• The data is represented and stored as objects which are similar to the objects used in the
object-oriented programming language.
• Advantages
– Complex data and a wider variety of data types.
– Easy to save and retrieve data quickly.
– Seamless integration with object-oriented programming languages.
– Easier to model the advanced real world problems.
– Extensible with custom data types.
• Disadvantages
– Not as widely adopted as relational databases.
– No universal data model. Lacks theoretical foundations and standards.
– Does not support views.
– High complexity causes performance issues.
– An adequate security mechanism and access rights to objects do not exist.
Hierarchical Databases
• Ensures that all data objects required by the database are accurately
represented.
• Omission of data will lead to creation of faulty reports and produce
incorrect results.
• A data model helps to design the database at the conceptual, physical
and logical levels.
• Data Model structure helps to define the relational tables, primary and
foreign keys and stored procedures.
• It provides a clear picture of the base data and can be used by database
developers to create a physical database.
• It is also helpful to identify missing and redundant data.
• Though the initial creation of data model is laborious and time
consuming, in the long run, it makes your IT infrastructure upgrade and
maintenance cheaper and faster.
Types of Data Model
• 1) Relational Data Model:
– This type of model designs the data in the form of rows
and columns within a table.
– Thus, a relational model uses tables for representing data
and in-between relationships.
– Tables are also called relations.
– This model was initially described by Edgar F. Codd, in
1969.
– The relational data model is the widely used model
which is primarily used by commercial data processing
applications.
Types of Data Model
• 2) Entity-Relationship Data Model:
– An ER model is the logical representation of data as objects and
relationships among them.
– These objects are known as entities, and relationship is an
association among these entities.
– This model was designed by Peter Chen and published in 1976.
– It was widely used in database designing.
– A set of attributes describe the entities.
– For example, student_name, student_id describes the 'student'
entity.
– A set of the same type of entities is known as an 'Entity set', and the
set of the same type of relationships is known as 'relationship set'.
Types of Data Model
• 3) Object-based Data Model:
– An extension of the ER model with notions of
functions, encapsulation, and object identity.
– This model supports a rich type system that
includes structured and collection types.
– In 1980, various database systems following the
object-oriented approach were developed.
– Here, the objects are nothing but the data carrying
its properties.
Types of Data Model
• 4) Semi-structured Data Model:
– This type of data model is different from the other three data
models.
– The semi-structured data model allows the data
specifications at places where the individual data items of
the same type may have different attributes sets.
– The Extensible Markup Language, also known as XML, is
widely used for representing the semi-structured data.
– Although XML was initially designed for including the
markup information to the text document, it gains
importance because of its application in the exchange of
data.
DBMS languages
• Database languages are used to read, update and store data in a
database. There are several such languages that can be used for this
purpose; one of them is SQL.
• Types of DBMS languages:
Data Definition Language (DDL)
customer loan
Loan
sanction
employee
Conversion of relationship sets:
• Multi-valued attributes:
– For each multivalued attribute ‘A’, we create a new relation R
that includes an attribute corresponding to plus the primary
key attributes k of the relation that represents the entity type
or relationship that has as an attribute.
– The primary key of R is then combination of A and k. For
example, if a STUDENT entity has rollno,name and phone
number where phone numer is a multivalued attribute then
create table PHONE(rollno,phoneno) where primary key is the
combination,
– In the STUDENT table we need not have phone number,
instead it can be simply (rollno,name) only.
Conversion of relationship sets:
• Converting Generalization /specification hierarchy to tables:
– A simple rule for conversion may be to decompose all the specialized
entities into table in case they are disjoint,
– for example, create 3 table as:
• Account(account_no,name,branch,balance)
• Saving account(account-no,intrest)
• Current_account(account-no,charges)
Database Index
• Speed up record search without having to
search every row in a database table
• Sorted list of a column value with pointer to
actual record
• Faster search and then look at only those
records linked to these indices, instead of
searching all records
Example
• Employee database with random ordering of
employee names, details and EMP_ID
• Searching for EMP_ID requires scanning all
records – long time
• Additional column with sorted EMP_ID and
pointer to original record in Table
• Faster search of EMP_ID using, say, binary
search. Extract associated employee record
SQL
• SQL is Structured Query Language, which is a
computer language for storing, manipulating and
retrieving data stored in a relational database.
• SQL is the standard language for Relational
Database System. All the Relational Database
Management Systems (RDMS) like MySQL, MS
Access, Oracle, Sybase, Informix, Postgres and
SQL Server use SQL as their standard database
language.
Why SQL?
• SQL is widely popular because it offers the following
advantages −
• Allows users to access data in the relational database
management systems.
• Allows users to describe the data.
• Allows users to define the data in a database and manipulate
that data.
• Allows to embed within other languages using SQL modules,
libraries & pre-compilers.
• Allows users to create and drop databases and tables.
• Allows users to create view, stored procedure, functions in a
database.
• Allows users to set permissions on tables, procedures and
views.
Characteristics of SQL
Example:
TRUNCATE TABLE employee;
SQL Data Manipulation Language (DML)
• Introduction to DML
• DML stands for Data Manipulation Language.
• It is a language used for selecting, inserting, deleting and
updating data in a database.
• It is used to retrieve and manipulate data in a relational
database.
• DML commands are as follows,
1. SELECT
2. INSERT
3. UPDATE
4. DELETE
DML performs read-only queries of data.
Basic Structure
ID NAME
1 abhi
2 adam
ID NAME
2 adam
Set difference(MINUS)
• The Minus operation combines results of two
SELECT statements and return only those in the
final result, which belongs to the first set of the
result.(returns unique records from table1)
The First table
ID NAME
1 abhi
2 adam
ID NAME
1 abhi
nested sub queries
• A Subquery or Inner query or a Nested query is
a query within another SQL query and
embedded within the WHERE clause.
• A subquery is used to return data that will be
used in the main query as a condition to further
restrict the data to be retrieved.
• Subqueries can be used with the SELECT, INSERT,
UPDATE, and DELETE statements along with the
operators like =, <, >, >=, <=, IN, BETWEEN, etc.
• There are a few rules that subqueries must follow −
• Subqueries must be enclosed within parentheses.
• A subquery can have only one column in the SELECT clause, unless
multiple columns are in the main query for the subquery to
compare its selected columns.
• An ORDER BY command cannot be used in a subquery, although
the main query can use an ORDER BY. The GROUP BY command
can be used to perform the same function as the ORDER BY in a
subquery.
• Subqueries that return more than one row can only be used with
multiple value operators such as the IN operator.
• A subquery cannot be immediately enclosed in a set function.
• The BETWEEN operator cannot be used with a subquery. However,
the BETWEEN operator can be used within the subquery.
• SELECT column_name [, column_name ]
FROM table1 [, table2 ] WHERE column_name
OPERATOR (SELECT column_name [,
column_name ] FROM table1 [, table2 ]
[WHERE])
Using GRANT and REVOKE