0% found this document useful (0 votes)
732 views

Notes On Database Management System

1) A database management system (DBMS) is software that allows users to create, access, manage and analyze data in a database. It provides tools for storing, organizing and retrieving data in a database. 2) A DBMS uses a 3-tier architecture that divides the system into physical, conceptual and external levels to provide data independence. This allows changes at one level without affecting other levels. 3) The entity-relationship (ER) model is used to design the logical structure of databases. It represents entities, attributes, relationships and keys that define the structure for storing and retrieving data from the database.

Uploaded by

Aditya Bafna
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
732 views

Notes On Database Management System

1) A database management system (DBMS) is software that allows users to create, access, manage and analyze data in a database. It provides tools for storing, organizing and retrieving data in a database. 2) A DBMS uses a 3-tier architecture that divides the system into physical, conceptual and external levels to provide data independence. This allows changes at one level without affecting other levels. 3) The entity-relationship (ER) model is used to design the logical structure of databases. It represents entities, attributes, relationships and keys that define the structure for storing and retrieving data from the database.

Uploaded by

Aditya Bafna
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Notes on

Database
Management
System

1|Page
 What is Data?
Data is nothing but facts and statistics stored or free flowing over a network, generally it's
raw and unprocessed. For example: When you visit any website, they might store you IP
address, that is data, in return they might add a cookie in your browser, marking you that you
visited the website, that is data, your name, it's data, your age, it's data.
Data becomes information when it is processed, turning it into something meaningful. Like,
based on the cookie data saved on user's browser, if a website can analyse that generally men
of age 20-25 visit us more, that is information, derived from the data collected.

 What is a Database?
A Database is a collection of related data organised in a way that data can be easily accessed,
managed and updated. Database can be software based or hardware based, with one sole
purpose, storing data.
During early computer days, data was collected and stored on tapes, which were mostly
write-only, which means once data is stored on it, it can never be read again. They were slow
and bulky, and soon computer scientists realised that they needed a better solution to this
problem.
Larry Ellison, the co-founder of Oracle was amongst the first few, who realised the need for
a software based Database Management System.

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

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

2|Page
 Advantages of DBMS

 Segregation of applicaion program.


 Minimal data duplicacy or data redundancy.
 Easy retrieval of data using the Query Language.
 Reduced development time and maintainance need.
 With Cloud Datacenters, we now have Database Management Systems capable of storing
almost infinite data.
 Seamless integration into the application programming languages which makes it very
easier to add a database to almost any application or website.

 Disadvantages of DBMS

 It's Complexity
 Except MySQL, which is open source, licensed DBMSs are generally costly.
 They are large in size.

 DBMS 3-tier Architecture

DBMS 3-tier architecture divides the complete system into three inter-related but
independent modules.

3|Page
Physical Level: At physical level, the information about location of database objects in data
store is kept. Various users of DBMS are unaware about the locations of these objects.
Conceptual Level: At conceptual level, data is represented in the form of various database
tables. For Example, STUDENT database may contain STUDENT and COURSE tables
which will be visible to users but users are unaware about their storage.
External Level: An external level specifies a view of the data in terms of conceptual level
tables. Each external level view is used to cater the needs of a particular category of users.
For Example, FACULTY of a university is interested in looking course details of students,
STUDENTS are interested in looking all details related to academics, accounts, courses and
hostel details as well. So, different views can be generated for different users.

 Data Independence
Data independence means change of data at one level should not affect another level. Two
types of data independence are present in this architecture:
Physical Data Independence: Any change in physical location of tables and indexes should
not affect conceptual level or external view of data. This data independence is easy to achieve
and implemented by most of the DBMS.
Conceptual Data Independence: The data at conceptual level schema and external level
schema must be independent. This means, change in conceptual schema should not affect
external schema. e.g.; Adding or deleting attributes of a table should not affect the user’s
view of table. But this type of independence is difficult to achieve as compared to physical
data independence because the changes in conceptual schema are reflected in user’s view.

 Data Abstraction and Data Independence

Database systems comprise of complex data-structures. In order to make the system efficient
in terms of retrieval of data, and reduce complexity in terms of usability of users, developers
use abstraction i.e. hide irrelevant details from the users. This approach simplifies database
design.
There are mainly 3 levels of data abstraction:
Physical: This is the lowest level of data abstraction. It tells us how the data is actually stored
in memory. The access methods like sequential or random access and file organisation
methods like B+ trees, hashing used for the same. Usability, size of memory, and the number
of times the records are factors which we need to know while designing the database.
Suppose we need to store the details of an employee. Blocks of storage and the amount of
memory used for these purposes is kept hidden from the user.

Logical: This level comprises of the information that is actually stored in the database in the
form of tables. It also stores the relationship among the data entities in relatively simple
structures. At this level, the information available to the user at the view level is unknown.
We can store the various attributes of an employee and relationships, e.g. with the manager
can also be stored.
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.
Users view data in the form of rows and columns. Tables and relations are used to store data.

4|Page
Multiple views of the same database may exist. Users can just view the data and interact with
the database, storage and implementation details are hidden from them.

The main purpose of data abstraction is achieving data independence in order to save time
and cost required when the database is modified or altered.
We have namely two levels of data independence arising from these levels of abstraction:
Physical level data independence: It refers to the characteristic of being able to modify the
physical schema without any alterations to the conceptual or logical schema, done for
optimisation purposes, e.g., Conceptual structure of the database would not be affected by
any change in storage size of the database system server. Changing from sequential to
random access files is one such example.These alterations or modifications to the physical
structure may include:
 Utilising new storage devices.
 Modifying data structures used for storage.
 Altering indexes or using alternative file organisation techniques etc.
Logical level data independence: It refers characteristic of being able to modify the logical
schema without affecting the external schema or application program. The user view of the
data would not be affected by any changes to the conceptual view of the data. These changes
may include insertion or deletion of attributes, altering table structures entities or
relationships to the logical schema etc.

 Database Management System | ER Model

ER Model is used to model the logical view of the system from data perspective which
consists of these components:
Entity, Entity Type, Entity Set –
An Entity may be an object with a physical existence – a particular person, car, house, or
employee – or it may be an object with a conceptual existence – a company, a job, or a
university course.
An Entity is an object of Entity Type and set of all entities is called as entity set. e.g.; E1 is an
entity having Entity Type Student and set of all students is called Entity Set. In ER diagram,
Entity Type is represented as:

5|Page
Attribute(s):
Attributes are the properties which define the entity type. For example, Roll_No, Name,
DOB, Age, Address, Mobile_No are the attributes which defines entity type Student. In ER
diagram, attribute is represented by an oval.

1. Key Attribute –
The attribute which uniquely identifies each entity in the entity set is called key
attribute.For example, Roll_No will be unique for each student. In ER diagram, key
attribute is represented by an oval with underlying lines.

2. Composite Attribute –
An attribute composed of many other attribute is called as composite attribute. For
example, Address attribute of student Entity type consists of Street, City, State, and
Country. In ER diagram, composite attribute is represented by an oval comprising of
ovals.

Multivalued Attribute –
An attribute consisting more than one value for a given entity. For example,
Phone_No (can be more than one for a given student). In ER diagram, multivalued
attribute is represented by double oval.

6|Page
Derived Attribute –
An attribute which can be derived from other attributes of the entity type is known as
derived attribute. e.g.; Age (can be derived from DOB). In ER diagram, derived
attribute is represented by dashed oval.

Relationship Type and Relationship Set:


A relationship type represents the association between entity types. For
example,‘Enrolled in’ is a relationship type that exists between entity type Student and
Course. In ER diagram, relationship type is represented by a diamond and connecting
the entities with lines.

Degree of a relationship set:


The number of different entity sets participating in a relationship set is called as degree of a
relationship set.
1. Unary Relationship –
When there is only ONE entity set participating in a relation, the relationship is
called as unary relationship. For example, one person is married to only one person.

Binary Relationship –
When there are TWO entities set participating in a relation, the relationship is called as
binary relationship.For example, Student is enrolled in Course.

n-ary Relationship –
When there are n entities set participating in a relation, the relationship is called as n-ary
relationship.

Cardinality:
The number of times an entity of an entity set participates in a relationship set is known
as cardinality.

Participation Constraint:
Participation Constraint is applied on the entity participating in the relationship set.

7|Page
1. Total Participation – Each entity in the entity set must participate in the relationship.
If each student must enroll in a course, the participation of student will be total. Total
participation is shown by double line in ER diagram.
2. Partial Participation – The entity in the entity set may or may NOT participate in
the relationship. If some courses are not enrolled by any of the student, the participation
of course will be partial.
The diagram depicts the ‘Enrolled in’ relationship set with Student Entity set having
total participation and Course Entity set having partial participation.

Weak Entity Type and Identifying Relationship:


As discussed before, an entity type has a key attribute which uniquely identifies each entity in
the entity set. But there exists some entity type for which key attribute can’t be defined.
These are called Weak Entity type.
For example, A company may store the information of dependants (Parents, Children,
Spouse) of an Employee. But the dependents don’t have existence without the employee. So
Dependent will be weak entity type and Employee will be Identifying Entity type for
Dependant.
A weak entity type is represented by a double rectangle. The participation of weak entity type
is always total. The relationship between weak entity type and its identifying strong entity
type is called identifying relationship and it is represented by double diamond.

Difference between Generalization and Specialization in DBMS

Generalization and Specialization both the terms are more common in Object Oriented
Technology, and they are also used in the Database with the same
features. Generalization occurs when we ignore the differences and acknowledge the
similarities between lower entities or child classes or relations (tables in DBMS) to form a
higher entity. However, when we moved on to the specialization, it spilt a higher entity to
form lower entities, then we discover the differences between those lower entities.

8|Page
Comparison Chart

BASIS FOR
GENERALIZATION SPECIALIZATION
COMPARISON

Basic It proceeds in a bottom-up It proceeds in a top-down manner.

manner.

Function Generalization extracts the Specialization splits an entity to form

common features of multiple multiple new entities that inherit

entities to form a new entity. some feature of the splitting entity.

Entities The higher level entity must have The higher level entity may not have

lower level entities. lower level entities.

Size Generalization reduces the size of Specialization increases the size of a

a schema. schema.

Application Generalization entities on group of Specialization is applied on a single

entities. entity.

Result Generalization results in forming a Specialization results in forming the

single entity from multiple multiple entity from a single entity.

entities.

9|Page
 Codd's Rule for Relational DBMS
E.F Codd was a Computer Scientist who invented the Relational model for Database
management. Based on relational model, the Relational database was created. Codd
proposed 13 rules popularly known as Codd's 12 rules to test DBMS's concept against his
relational model. Codd's rule actualy define what quality a DBMS requires in order to
become a Relational Database Management System (RDBMS). Till now, there is hardly any
commercial product that follows all the 13 Codd's rules. Even Oracle follows only eight and
half (8.5) out of 13. The Codd's 12 rules are as follows.

Rule zero
This rule states that for a system to qualify as an RDBMS, it must be able to manage
database entirely through the relational capabilities.

Rule 1: Information rule


All information (including metadata) is to be represented as stored data in cells of tables. The
rows and columns have to be strictly unordered.

Rule 2: Guaranted Access


Each unique piece of data(atomic value) should be accesible by : Table Name + Primary
Key(Row) + Attribute(column).
NOTE: Ability to directly access via POINTER is a violation of this rule.

Rule 3: Systematic treatment of NULL


Null has several meanings, it can mean missing data, not applicable or no value. It should be
handled consistently. Also, Primary key must not be null, ever. Expression on NULL must
give null.

Rule 4: Active Online Catalog


Database dictionary (catalog) is the structure description of the complete Database and it
must be stored online. The Catalog must be governed by same rules as rest of the database.
The same query language should be used on catalog as used to query database.

Rule 5: Powerful and Well-Structured Language


One well-structured language must be there to provide all manners of access to the data
stored in the database. Example: SQL, etc. If the database allows access to the data without
the use of this language, then that is a violation.

Rule 6: View Updation Rule


All the view that are theoretically updatable should be updatable by the system as well.

10 | P a g e
Rule 7: Relational Level Operation
There must be Insert, Delete, and Update operations at each level of relations. Set operation
like Union, Intersection and minus should also be supported.

Rule 8: Physical Data Independence


The physical storage of data should not matter to the system. If say, some file supporting
table is renamed or moved from one disk to another, it should not affect the application.

Rule 9: Logical Data Independence


If there is change in the logical structure (table structures) of the database the user view of
data should not change. Say, if a table is split into two tables, a new view should give result
as the join of the two tables. This rule is most difficult to satisfy.

Rule 10: Integrity Independence


The database should be able to enforce its own integrity rather than using other programs.
Key and Check constraints, trigger etc, should be stored in Data Dictionary. This also
make RDBMS independent of front-end.

Rule 11: Distribution Independence


A database should work properly regardless of its distribution across a network. Even if a
database is geographically distributed, with data stored in pieces, the end user should get an
impression that it is stored at the same place. This lays the foundation of distributed
database.

Rule 12: Nonsubversion Rule


If low level access is allowed to a system it should not be able to subvert or bypass integrity
rules to change the data. This can be achieved by some sort of looking or encryption.

 Constraints in DBMS-

 Relational constraints are the restrictions imposed on the database contents and operations.
 They ensure the correctness of data in the database.

 Types of Constraints in DBMS-

In DBMS, there are following 5 different types of relational constraints-

11 | P a g e
1. Domain constraint
2. Tuple Uniqueness constraint
3. Key constraint
4. Entity Integrity constraint
5. Referential Integrity constraint

1. Domain Constraint-

 Domain constraint defines the domain or set of values for an attribute.


 It specifies that the value taken by the attribute must be the atomic value from its domain.

Example-
Consider the following Student table-
STU_ID Name Age
S001 Akshay 20
S002 Abhishek 21
S003 Shashank 20
S004 Rahul A

Here, value ‘A’ is not allowed since only integer values can be taken by the age attribute.

12 | P a g e
2. Tuple Uniqueness Constraint-

Tuple Uniqueness constraint specifies that all the tuples must be necessarily unique in any
relation.

Example-01:

Consider the following Student table-


STU_ID Name Age
S001 Akshay 20
S002 Abhishek 21
S003 Shashank 20
S004 Rahul 20

This relation satisfies the tuple uniqueness constraint since here all the tuples are unique.

Example-02:

Consider the following Student table-


STU_ID Name Age
S001 Akshay 20
S001 Akshay 20
S003 Shashank 20
S004 Rahul 20

This relation does not satisfy the tuple uniqueness constraint since here all the tuples are not
unique.

3. Key Constraint-

Key constraint specifies that in any relation-


 All the values of primary key must be unique.
 The value of primary key must not be null.

13 | P a g e
Example-

Consider the following Student table-


STU_ID Name Age
S001 Akshay 20
S001 Abhishek 21
S003 Shashank 20
S004 Rahul 20

This relation does not satisfy the key constraint as here all the values of primary key are not
unique.

4. Entity Integrity Constraint-

 Entity integrity constraint specifies that no attribute of primary key must contain a null
value in any relation.
 This is because the presence of null value in the primary key violates the uniqueness
property.

Example-

Consider the following Student table-


STU_ID Name Age
S001 Akshay 20
S002 Abhishek 21
S003 Shashank 20
Rahul 20

This relation does not satisfy the entity integrity constraint as here the primary key contains a
NULL value.

5. Referential Integrity Constraint-

 This constraint is enforced when a foreign key references the primary key of a relation.
 It specifies that all the values taken by the foreign key must either be available in the
relation of the primary key or be null.

14 | P a g e
Important Results-

The following two important results emerges out due to referential integrity constraint-
 We can not insert a record into a referencing relation if the corresponding record does not
exist in the referenced relation.
 We can not delete or update a record of the referenced relation if the corresponding record
exists in the referencing relation.

Example-

Consider the following two relations- ‘Student’ and ‘Department’.


Here, relation ‘Student’ references the relation ‘Department’.

Student
STU_ID Name Dept_no
S001 Akshay D10
S002 Abhishek D10
S003 Shashank D11
S004 Rahul D14

Department
Dept_name Dept_name Dept_name
Dept_name Dept_name Dept_name
Dept_name Dept_name Dept_name
Dept_name Dept_name Dept_name
Dept_name Dept_name Dept_name

15 | P a g e
Here,
 The relation ‘Student’ does not satisfy the referential integrity constraint.
 This is because in relation ‘Department’, no value of primary key specifies department no.
14.
 Thus, referential integrity constraint is violated.

 What is SQL

o SQL stands for Structured Query Language.


o It is designed for managing data in a relational database management system
(RDBMS).
o It is pronounced as S-Q-L or sometime See-Qwell.
o SQL is a database language, it is used for database creation, deletion, fetching rows,
and modifying rows, etc.
o SQL is based on relational algebra and tuple relational calculus.
o SQL is not case sensitive. Generally SQL keywords are written in uppercase.
o SQL statements are dependent on text lines. We can place a single SQL statement on
one or multiple text lines.
o You can perform most of the action in a database with SQL statements.
o SQL depends on relational algebra and tuple relational calculus.
o

All DBMS like MySQL, Oracle, MS Access, Sybase, Informix, Postgres, and SQL Server
use SQL as standard database language.

 Data Integrity

There are the following categories of data integrity exist with each RDBMS:

Entity integrity: It specifies that there should be no duplicate rows in a table.

Domain integrity: It enforces valid entries for a given column by restricting the type, the
format, or the range of values.

Referential integrity: It specifies that rows cannot be deleted, which are used by other
records.

User-defined integrity: It enforces some specific business rules that are defined by users.
These rules are different from entity, domain or referential integrity.

16 | P a g e
 Difference between DBMS and RDBMS

Although DBMS and RDBMS both are used to store information in physical database but
there are some remarkable differences between them.

The main differences between DBMS and RDBMS are given below:

No. DBMS RDBMS


1) DBMS applications store data RDBMS applications store data
as file. in a tabular form.
2) In DBMS, data is generally In RDBMS, the tables have an
stored in either a hierarchical identifier called primary key
form or a navigational form. and the data values are stored
in the form of tables.
3) Normalization is not present in Normalization is present in
DBMS. RDBMS.
4) DBMS does not apply any RDBMS defines the integrity
security with regards to data constraint for the purpose of
manipulation. ACID (Atomocity, Consistency,
Isolation and Durability)
property.
5) DBMS uses file system to store in RDBMS, data values are
data, so there will be no stored in the form of tables, so
relation between the tables. a relationship between these
data values will be stored in
the form of a table as well.
6) DBMS has to provide some RDBMS system supports a
uniform methods to access the tabular structure of the data
stored information. and a relationship between
them to access the stored
information.
7) DBMS does not support RDBMS supports distributed
distributed database. database.
8) DBMS is meant to be for small RDBMS is designed to handle
organization and deal with large amount of data. it
small data. it supports single supports multiple users.
user.
9) Examples of DBMS are file Example of RDBMS are mysql,
systems, xml etc. postgre, sql server, oracle etc.

 SQL Commands

These are the some important SQL command:

SELECT: it extracts data from a database.

UPDATE: it updates data in database.

17 | P a g e
DELETE: it deletes data from database.

CREATE TABLE: it creates a new table.

ALTER TABLE: it is used to modify the table.

DROP TABLE: it deletes a table.

CREATE DATABASE: it creates a new database.

ALTER DATABASE: It is used to modify a database.

INSERT INTO: it inserts new data into a database.

CREATE INDEX: it is used to create an index (search key).

DROP INDEX: it deletes an index.

 SQL Logical Operators:

This is the list of logical operators used in SQL.

Operator Description
ALL this is used to compare a value to all values in another value set.
AND this operator allows the existence of multiple conditions in an SQL statement.
ANY this operator is used to compare the value in list according to the condition.
BETWEEN this operator is used to search for values, that are within a set of values
IN this operator is used to compare a value to that specified list value
NOT the NOT operator reverse the meaning of any logical operator
OR this operator is used to combine multiple conditions in SQL statements
EXISTS the EXISTS operator is used to search for the presence of a row in a specified table
LIKE this operator is used to compare a value to similar values using wildcard operator

 SQL JOIN

As the name shows, JOIN means to combine something. In case of SQL, JOIN means "to
combine two or more tables".

The SQL JOIN clause takes records from two or more tables in a database and combines it
together.

ANSI standard SQL defines five types of JOIN :

1. inner join,
2. left outer join,
3. right outer join,

18 | P a g e
4. full outer join, and
5. cross join.

In the process of joining, rows of both tables are combined in a single table.

 Why SQL JOIN is used?

If you want to access more than one table through a select statement.

If you want to combine two or more table then SQL JOIN statement is used .it combines rows
of that tables in one table and one can retrieve the information by a SELECT statement.

The joining of two or more tables is based on common field between them.

SQL INNER JOIN also known as simple join is the most common type of join.

 SQL PRIMARY KEY

A column or columns is called primary key (PK) that uniquely identifies each row in the
table.

If you want to create a primary key, you should define a PRIMARY KEY constraint when
you create or modify a table.

When multiple columns are used as a primary key, it is known as composite primary key.

In designing the composite primary key, you should use as few columns as possible. It is
good for storage and performance both, the more columns you use for primary key the more
storage space you require.

Inn terms of performance, less data means the database can process faster.

 Points to remember for primary key:


o Primary key enforces the entity integrity of the table.
o Primary key always has unique data.
o A primary key length cannot be exceeded than 900 bytes.
o A primary key cannot have null value.
o There can be no duplicate value for a primary key.
o A table can contain only one primary key constraint.

19 | P a g e
 Difference between primary key and foreign key in SQL:

These are some important difference between primary key and foreign key in SQL-

Primary key cannot be null on the other hand foreign key can be null.

Primary key is always unique while foreign key can be duplicated.

Primary key uniquely identify a record in a table while foreign key is a field in a table that is
primary key in another table.

There is only one primary key in the table on the other hand we can have more than one
foreign key in the table.

By default primary key adds a clustered index on the other hand foreign key does not
automatically create an index, clustered or non-clustered. You must manually create an index
for foreign key.

 SQL Composite Key

A composite key is a combination of two or more columns in a table that can be used to
uniquely identify each row in the table when the columns are combined uniqueness is
guaranteed, but when it taken individually it does not guarantee uniqueness.

Sometimes more than one attributes are needed to uniquely identify an entity. A primary key
that is made by the combination of more than one attribute is known as a composite key.

In other words we can say that:

Composite key is a key which is the combination of more than one field or column of a given
table. It may be a candidate key or primary key.

Columns that make up the composite key can be of different data types.

 Unique Key in SQL

A unique key is a set of one or more than one fields/columns of a table that uniquely identify
a record in a database table.

You can say that it is little like primary key but it can accept only one null value and it cannot
have duplicate values.

The unique key and primary key both provide a guarantee for uniqueness for a column or a
set of columns.

There is an automatically defined unique key constraint within a primary key constraint.

There may be many unique key constraints for one table, but only one PRIMARY KEY
constraint for one table.

20 | P a g e
 Alternate Key in SQL

Alternate key is a secondary key it can be simple to understand by an example:

Let's take an example of student it can contain NAME, ROLL NO., ID and CLASS.

Here ROLL NO. is primary key and rest of all columns like NAME, ID and CLASS are
alternate keys.

If a table has more than one candidate key, one of them will become the primary key and rest
of all are called alternate keys.

In simple words, you can say that any of the candidate key which is not part of primary key is
called an alternate key. So when we talk about alternate key, the column may not be primary
key but still it is a unique key in the column.

 SQL vs NoSQL

There are a lot of databases used today in the industry. Some are SQL databases, some are
NoSQL databases. The conventional database is SQL database system that uses tabular
relational model to represent data and their relationship. The NoSQL database is the newer
one database that provides a mechanism for storage and retrieval of data other than tabular
relations model used in relational databases.

Following is a list of differences between SQL and NoSQL database:

Index SQL NoSQL


1) Databases are categorized as Relational NoSQL databases are categorized as Non-
Database Management System (RDBMS). relational or distributed database system.
2) SQL databases have fixed or static or NoSQL databases have dynamic schema.
predefined schema.
3) SQL databases display data in form of NoSQL databases display data as
tables so it is known as table-based collection of key-value pair, documents,
database. graph databases or wide-column stores.
4) SQL databases are vertically scalable. NoSQL databases are horizontally
scalable.
5) SQL databases use a powerful language In NoSQL databases, collection of
"Structured Query Language" to define and documents are used to query the data. It
manipulate the data. is also called unstructured query
language. It varies from database to
database.
6) SQL databases are best suited for complex NoSQL databases are not so good for
queries. complex queries because these are not as
powerful as SQL queries.
7) SQL databases are not best suited for NoSQL databases are best suited for
hierarchical data storage. hierarchical data storage.
8) MySQL, Oracle, Sqlite, PostgreSQL and MS- MongoDB, BigTable, Redis, RavenDB,
SQL etc. are the example of SQL database. Cassandra, Hbase, Neo4j, CouchDB etc.
are the example of nosql database

21 | P a g e
 Difference between DELETE and TRUNCATE statement in SQL

The main differences between SQL DELETE and TRUNCATE statements are given below:

No. DELETE TRUNCATE


1) DELETE is a DML command. TRUNCATE is a DDL command.
2) We can use WHERE clause in DELETE We cannot use WHERE clause with
command. TRUNCATE
3) DELETE statement is used to delete a TRUNCATE statement is used to remove all
row from a table the rows from a table.
4) DELETE is slower than TRUNCATE TRUNCATE statement is faster than DELETE
statement. statement.
5) You can rollback data after using It is not possible to rollback after using
DELETE statement. TRUNCATE statement.

 What is ACID property in a database?

ACID property is used to ensure that the data transactions are processed reliably in a database
system.

A single logical operation of a data is called transaction.

ACID is an acronym for Atomicity, Consistency, Isolation, Durability.

Atomicity: it requires that each transaction is all or nothing. It means if one part of the
transaction fails, the entire transaction fails and the database state is left unchanged.

Consistency: the consistency property ensure that the data must meet all validation rules. In
simple words you can say that your transaction never leaves your database without
completing its state.

Isolation: this property ensure that the concurrent property of execution should not be met.
The main goal of providing isolation is concurrency control.

Durability: durability simply means that once a transaction has been committed, it will
remain so, come what may even power loss, crashes or errors.

 Normalization

o Normalization is the process of organizing the data in the database.


o Normalization is used to minimize the redundancy from a relation or set of relations.
It is also used to eliminate the undesirable characteristics like Insertion, Update and
Deletion Anomalies.
o Normalization divides the larger table into the smaller table and links them using
relationship.
o The normal form is used to reduce redundancy from the database table.

22 | P a g e
Normal Form Description
1NF A relation is in 1NF if it contains an atomic value.
2NF A relation will be in 2NF if it is in 1NF and all non-key attributes
are fully functional dependent on the primary key.
3NF A relation will be in 3NF if it is in 2NF and no transition
dependency exists.
4NF A relation will be in 4NF if it is in Boyce Codd normal form and
has no multi-valued dependency.
5NF A relation is in 5NF if it is in 4NF and not contains any join
dependency and joining should be lossless.

 Normalization Rule
Normalization rules are divided into the following normal forms:

1. First Normal Form


2. Second Normal Form
3. Third Normal Form
4. BCNF
5. Fourth Normal Form

 First Normal Form (1NF)


For a table to be in the First Normal Form, it should follow the following 4 rules:

1. It should only have single(atomic) valued attributes/columns.


2. Values stored in a column should be of the same domain
3. All the columns in a table should have unique names.
4. And the order in which data is stored, does not matter.

 Second Normal Form (2NF)


For a table to be in the Second Normal Form,

1. It should be in the First Normal form.


2. And, it should not have Partial Dependency.

23 | P a g e
 Third Normal Form (3NF)
A table is said to be in the Third Normal Form when,

1. It is in the Second Normal form.


2. And, it doesn't have Transitive Dependency.

 Boyce and Codd Normal Form (BCNF)


Boyce and Codd Normal Form is a higher version of the Third Normal form. This form
deals with certain type of anomaly that is not handled by 3NF. A 3NF table which does not
have multiple overlapping candidate keys is said to be in BCNF. For a table to be in BCNF,
following conditions must be satisfied:

1. R must be in 3rd Normal Form


2. and, for each functional dependency ( X → Y ), X should be a super Key.

 Fourth Normal Form (4NF)


A table is said to be in the Fourth Normal Form when,

1. It is in the Boyce-Codd Normal Form.


2. And, it doesn't have Multi-Valued Dependency.

24 | P a g e

You might also like