SQL (Structured Query Language) Is Used To Perform Operations On The Records Stored in The Database
SQL (Structured Query Language) Is Used To Perform Operations On The Records Stored in The Database
SQL (Structured Query Language) Is Used To Perform Operations On The Records Stored in The Database
SQL (Structured Query Language) is used to perform operations on the records stored in the database
such as updating records, deleting records, creating and modifying tables, views, etc.
SQL is just a query language; it is not a database. To perform SQL queries, you need to install any
database, for example, Oracle, MySQL, MongoDB, PostGre SQL, SQL Server, DB2, etc.
What is SQL?
SQL is required:
o With SQL, we can query our database in several ways, using English-like statements.
o With SQL, a user can access data from a relational database management system.
o It allows the user to describe the data.
o It allows the user to define the data in the database and manipulate it when needed.
o It allows the user to create and drop database and table.
o It allows the user to create a view, stored procedure, function in a database.
o It allows the user to set permission on tables, procedures, and views.
Syntax:
SELECT "column_name" FROM "table_name";
Commands:
1. CREATE:
CREATE DATABASE database_name;
2. DROP
SQL DROP statement is used to delete or remove indexes from a table in the database.
If you want to delete or drop an existing database in a SQL schema, you can use SQL DROP
DATABASE
DROP DATABASE database_name;
3. RENAME
SQL RENAME DATABASE is used when you need to change the name of your database. Sometimes it
is used because you think that the original name is not more relevant to the database or you want
to give a temporary name to that database.
RENAME DATABASE old_db_name TO new_db_name;
4. SELECT Database
In MySQL database, you need to select a database first before executing any query on table, view
etc.
USE database_name;
Table:
Table is a collection of data, organized in terms of rows and columns. In DBMS terms, table is known
as relation and row as tuple. Table is the simple form of data storage. A table is also considered as a
convenient representation of relations.
A table can have specified number of columns, but can have any number of rows.
Employee
Salary
Here, "Employee" is the table name, "EMP_NAME", "ADDRESS" and "SALARY" are the column names.
The combination of data of multiple columns forms a row e.g. "Ankit", "Lucknow" and 15000 are the
data of one row.
If you want to create a table, you should name the table and define its column and each column's data
type.
Syntax: create table "tablename"
("column1" "data type",
"column2" "data type",
"column3" "data type",
...
"columnN" "data type");
Ex: CREATE TABLE Employee
(
EmployeeID int,
FirstName varchar(255),
LastName varchar(255),
Email varchar(255),
AddressLine varchar(255),
City varchar(255)
);
We can create a copy of an existing table using the create table command. The new table gets the same
column signature as the old table. We can select all columns or some specific columns.
If we create a new table using an old table, the new table will be filled with the existing value from the
old table.
CREATE TABLE EmployeeCopy AS
SELECT EmployeeID, FirstName, Email
FROM Employee;
The following query creates a PRIMARY KEY on the "D" column when the "Employee" table is created.
CREATE TABLE Employee(
EmployeeID int NOT NULL,
FirstName varchar(255) NOT NULL,
LastName varchar(255),
City varchar(255),
PRIMARY KEY (EmployeeID)
);
Use the following query to define a PRIMARY KEY constraints on multiple columns, and to allow naming
of a PRIMARY KEY constraints.
CREATE TABLE Employee(
EmployeeID NOT NULL,
FirstName varchar(255) NOT NULL,
LastName varchar(255),
City varchar(255),
CONSTRAINT PK_Employee PRIMARY KEY (EmployeeID, FirstName)
);
A SQL DROP TABLE statement is used to delete a table definition and all data from a table.
This is very important to know that once a table is deleted all the information available in the table is
lost forever, so we have to be very careful when using this command.
DROP TABLE "table_name";
The DELETE statement is used to delete rows from a table. If you want to remove a specific row from a
table you should use WHERE condition.
DELETE FROM table_name [WHERE condition];
But if you do not specify the WHERE condition it will remove all the rows from the table.
DELETE FROM table_name;
There is a slight difference b/w delete and truncate statement. The DELETE statement only deletes the
rows from the table based on the condition defined by WHERE clause or delete all the rows from the
table when condition is not specified.
The TRUNCATE statement: it is used to delete all the rows from the table and free the containing space.
TRUNCATE TABLE employee;
When you use the drop statement it deletes the table's row together with the table's definition so all
the relationships of that table with other tables will no longer be valid.
On the other hand when we TRUNCATE a table, the table structure remains the same, so you will not
face any of the above problems.
SQL RENAME TABLE syntax is used to change the name of a table. If we choose a non-meaningful name
for the table, it is required to be changed.
ALTER TABLE table_name
RENAME TO new_table_name;
Ex: ALTER TABLE STUDENTS
RENAME TO ARTISTS;
The ALTER TABLE statement is used to add, modify or delete columns in an existing table. It is also used
to rename a table.
You can also use SQL ALTER TABLE command to add and drop various constraints on an existing table.
If you want to add columns in SQL table, the SQL alter table syntax is:
ALTER TABLE table_name ADD column_name column-definition;
If you want to add multiple columns in table, the SQL table will be:
ALTER TABLE table_name
ADD (column_1 column-definition,
column_2 column-definition,
.....
column_n column-definition);
DML Statements:
-SELECT statement:
The most commonly used SQL command is SELECT statement. It is used to query the database and
retrieve selected data that follow the conditions we want.
In simple words, we can say that the select statement used to query or retrieve data from a table in the
database.
SELECT expressions
FROM tables
WHERE conditions;
[GROUP BY Clause] : Groups rows that share a property so that the aggregate function can be applied to
each group.
[HAVING Clause] : It selects among the groups defined by the GROUP BY clause.
Ex:
SELECT first_name FROM student_details;
INSERT Statement:
SQL INSERT statement is a SQL query. It is used to insert a single or a multiple records in a table.
Syntax:
INSERT INTO table_name
VALUES (value1, value2, value3....);
Ex:
INSERT INTO STUDENTS (ROLL_NO, NAME, AGE, CITY)
VALUES (1, ‘ABHIRAM’, 22, ‘ALLAHABAD’);
UPDATE Statement:
The SQL commands (UPDATE and DELETE) are used to modify the data that is already in the database.
The SQL DELETE command uses a WHERE clause.
SQL UPDATE statement is used to change the data of the records held by tables. The rows that need to
be updated are decided by a condition. To specify the condition, we use WHERE clause.
Syntax:
UPDATE table_name
SET column_name = expression
WHERE conditions
////SET SQL_SAFE_UPDATES = 0;
‘WHERE’ Clause:
WHERE clauses are not mandatory clauses of SQL DML statements. But it can be used to limit the
number of rows affected by a SQL DML statement or returned by a query.
It filters the records. It returns only those queries which fulfill the specific conditions. WHERE clause is
used in SELECT, UPDATE, DELETE statement etc.
SELECT column1, column 2, ... column n
FROM table_name
WHERE [conditions]
The SQL AND condition is used in SQL query to create two or more conditions to be met. It is used in SQL
SELECT, INSERT, UPDATE and DELETE statements.
SELECT columns
FROM tables
WHERE condition 1
AND condition 2;
SELECT DISTINCT:
The SQL DISTINCT command is used with SELECT key word to retrieve only distinct or unique data.
In a table, there may be a chance to exist a duplicate value and sometimes we want to retrieve only
unique values. In such scenarios, SQL SELECT DISTINCT statement is used.
Syntax:
SELECT DISTINCT column_name ,column_name
FROM table_name;
Ex:
Here is a table of students from where we want to retrieve distinct information For example: distinct
home-town.
SELECT DISTINCT home_town
FROM students
HOME_TOW
N
Lucknow
Varanasi
The SQL COUNT() function is used to return the number of rows in a query. The COUNT() function is
used with SQL SELECT statement and it is very useful to count the number of rows in a table having
enormous data.
SELECT COUNT(*) FROM employee_table;
SELECT COUNT(ProductID)
FROM Products;
AVG():
Ex: SELECT AVG(Price)
FROM Products;
Ex: SELECT * FROM Customers
WHERE CustomerName LIKE 'a%'; // Alex, Abraham, Alekhya, Andy- Alex, Alekhya
Ex: SELECT * FROM Customers
WHERE CustomerName LIKE '%a'; // ‘a%i’, ‘a_ex’, ‘%fany’
ALIAS:
SQL aliases are used to give a table, or a column in a table, a temporary name. Aliases are often used to
make column names more readable.
An alias only exists for the duration of that query. An alias is created with the AS keyword.
SELECT CustomerID AS ID, CustomerName AS Customer
FROM Customers;
Select Top:
The SQL SELECT TOP Statement is used to select top data from a table. The top clause specifies that how
many rows are returned.
Ex: SELECT TOP 2 * FROM employee
ORDER BY Clause:
The SQL ORDER BY clause is used for sorting data in ascending and descending order based on one or
more columns.
The ORDER BY keyword sorts the records in ascending order by default. To sort the records in
descending order, use the DESC keyword.
Syntax:
SELECT column1, column2,...
FROM table_name
ORDER BY column1, column2, ... ASC|DESC;
Ex: SELECT * FROM Customers
ORDER BY Country;
The following SQL statement selects all customers from the "Customers" table, sorted by the "Country"
and the "CustomerName" column. This means that it orders by Country, but if some rows have the same
Country, it orders them by CustomerName.
Ex: SELECT * FROM Customers
ORDER BY Country, CustomerName;
SELECT * FROM Customers
ORDER BY Country ASC, CustomerName DESC;
GROUP BY Statement:
The GROUP BY statement groups rows that have the same values into summary rows, like "find the
number of customers in each country".
Syntax: SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
ORDER BY column_name(s);
Ex:
Orders Table
OrderID CustomerID EmployeeID OrderDate ShipperID
10248 90 5 1996-07-04 3
10249 81 6 1996-07-05 1
10250 34 4 1996-07-08 2
Shippers Table:
ShipperID ShipperName
1 Speedy Express
2 United Package
3 Federal Shipping
GROUP BY ShipperName;
Output:
Number of Records: 3
ShipperName NumberOfOrders
Federal Shipping 68
Speedy Express 54
United Package 74
The following SQL statement lists the number of customers in each country, sorted high to low:
SELECT COUNT(CustomerID), Country
FROM Customers
GROUP BY Country
ORDER BY COUNT(CustomerID) DESC;
HAVING:
The HAVING clause was added to SQL because the WHERE keyword cannot be used with aggregate
functions.
Syntax: SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
HAVING condition
ORDER BY column_name(s);
Ex: The following SQL statement lists the number of customers in each country. Only include countries
with more than 5 customers
SELECT COUNT(CustomerID), Country
FROM Customers
GROUP BY Country
HAVING COUNT(CustomerID) > 5;
The following SQL statement lists the number of customers in each country, sorted high to low (Only
include countries with more than 5 customers).
SELECT COUNT(CustomerID), Country
FROM Customers
GROUP BY Country
HAVING COUNT(CustomerID) > 5
ORDER BY COUNT(CustomerID) DESC;
DATA TYPES:
Numeric Data Types: bit, boolean, smallint, int, float, double, decimal.
MySQL comes with the following data types for storing a date or a date/time value in the database:
Inside a table, a column often contains many duplicate values; and sometimes you only want to list the
different (distinct) values.
Ex: SELECT DISTINCT Country FROM Customers;
SELECT COUNT(DISTINCT Country) FROM Customers;
SQL JOINS:
A JOIN clause is used to combine rows from two or more tables, based on a related column between
them.
Orders table:
10308 2 1996-09-18
10309 37 1996-09-19
10310 77 1996-09-20
Customers table:
Notice that the "CustomerID" column in the "Orders" table refers to the "CustomerID" in the
"Customers" table. The relationship between the two tables above is the "CustomerID" column.
Then, we can create the following SQL statement (that contains an INNER JOIN), that selects records
that have matching values in both tables.
Result:
(INNER) JOIN: Returns records that have matching values in both tables
LEFT (OUTER) JOIN: Returns all records from the left table, and the matched records from the
right table
RIGHT (OUTER) JOIN: Returns all records from the right table, and the matched records from the
left table
FULL (OUTER) JOIN: Returns all records when there is a match in either left or right table
Syntax: SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name = table2.column_name;
Ex:
SELECT Customers.CustomerName, Orders.OrderID
FROM Customers
LEFT JOIN Orders ON Customers.CustomerID = Orders.CustomerID
ORDER BY Customers.CustomerName;
The FULL OUTER JOIN keyword returns all records when there is a match in left (table1) or right (table2)
table records.
PRIMARY KEY:
The PRIMARY KEY constraint uniquely identifies each record in a table. Primary keys must contain
UNIQUE values, and cannot contain NULL values.
A table can have only ONE primary key; and in the table, this primary key can consist of single or
multiple columns (fields).
Ex: CREATE TABLE Persons (
ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
PRIMARY KEY (ID)
);
To allow naming of a PRIMARY KEY constraint, and for defining a PRIMARY KEY constraint on multiple
columns, use the following SQL syntax:
Ex: CREATE TABLE Persons (
ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
CONSTRAINT PK_Person PRIMARY KEY (ID,LastName)
);
To create a PRIMARY KEY constraint on the "ID" column when the table is already created, use the
following:
ALTER TABLE Persons
ADD PRIMARY KEY (ID);
ALTER TABLE Persons
ADD CONSTRAINT PK_Person PRIMARY KEY (ID,LastName);
If you use ALTER TABLE to add a primary key, the primary key column(s) must have been declared to not
contain NULL values (when the table was first created).
ALTER TABLE Persons
DROP PRIMARY KEY;
FOREIGN KEY:
A FOREIGN KEY is a field (or collection of fields) in one table that refers to the PRIMARY KEY in another
table. The table with the foreign key is called the child table and the table with the primary key is called
the referenced or parent table.
The FOREIGN KEY constraint prevents invalid data from being inserted into the foreign key column,
because it has to be one of the values contained in the parent table.
Ex: CREATE TABLE Orders (
OrderID int NOT NULL UNIQUE,
OrderNumber int NOT NULL UNIQUE,
PersonID int UNIQUE,
PRIMARY KEY (OrderID),
FOREIGN KEY (PersonID) REFERENCES Persons(PersonID)
);
To allow naming of a FOREIGN KEY constraint, and for defining a FOREIGN KEY constraint on multiple
columns, use the following :
Ex: CREATE TABLE Orders (
OrderID int NOT NULL,
OrderNumber int NOT NULL,
PersonID int,
PRIMARY KEY (OrderID),
CONSTRAINT FK_PersonOrder
FOREIGN KEY (PersonID, Email) REFERENCES Persons(PersonID)
);
The UNIQUE constraint ensures that all values in a column are different. Both the UNIQUE and PRIMARY
KEY constraints provide a guarantee for uniqueness for a column or set of columns.
However, you can have many UNIQUE constraints per table, but only one PRIMARY KEY constraint per
table.
Ex: CREATE TABLE Persons (
ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
UNIQUE (ID)
);
By default, a column can hold NULL values. The NOT NULL constraint enforces a column to NOT accept
NULL values.
Ex: CREATE TABLE Persons (
ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255) NOT NULL,
Age int
);
SQL SUBQUERY:
In SQL a Subquery can be simply defined as a query within another query. In other words we can say
that a Subquery is a query that is embedded in WHERE clause of another SQL query.
Important rules for Subqueries:
You can place the Subquery in a number of SQL clauses: WHERE clause, HAVING clause, FROM
clause.
Subqueries can be used with SELECT, UPDATE, INSERT, DELETE statements along with expression
operator. It could be equality operator or comparison operator such as =, >, =, <= and Like operator.
A subquery is a query within another query. The outer query is called as main query and inner
query is called as subquery.
The subquery generally executes first, and its output is used to complete the query condition for
the main or outer query.
Subquery must be enclosed in parentheses.
Subqueries are on the right side of the comparison operator.
ORDER BY command cannot be used in a Subquery. GROUPBY command can be used to perform
same function as ORDER BY command.
Use single-row operators with singlerow Subqueries. Use multiple-row operators with multiple-
row Subqueries.
Subqueries are seen to be used most frequently with SELECT statement as below:
Sumath
i 105 Kanchipuram 8989856868
STUDENT Table
NAME ROLL_NOSECTION
Ravi 104 A
Sumath
i 105 B
Raj 102 A
To display NAME, LOCATION, PHONE_NUMBER of the students from DATABASE table whose section is
A,
First subquery executes “ SELECT ROLL_NO from STUDENT where SECTION=’A’ ” and returns ROLL_NO
from STUDENT table whose SECTION is ‘A’. Then outer-query executes it and returns the NAME,
LOCATION, PHONE_NUMBER from the DATABASE table of the student whose ROLL_NO is returned from
inner subquery.
Output:
NAM
E ROLL_NO LOCATION PHONE_NUMBER
RANK():
The ranking functions in MySql are used to rank each row of a partition. The ranking functions are also
part of MySQL windows functions list.
These functions are always used with OVER() clause.
The ranking functions always assign rank on basis of ORDER BY clause.
The rank is assigned to rows in a sequential manner.
The assignment of rank to rows always start with 1 for every new partition.
Table: result
Ankita Science 80
Ankita Maths 65
Pratibha Science 80
Swarna Science 50
Pratibha English 70
Swarna Maths 85
Ankita English 90
1. dense_rank() function-
English Ankita 90 2
Pratibh
English a 70 3
Pratibh
Maths a 100 1
Subject Mar Dense_ran
s Name k k
Maths Swarna 85 2
Maths Ankita 65 3
Science Ankita 80 1
Pratibh
Science a 80 1
Science Swarna 50 2
2. rank() function-
SELECT subjects, s_name, mark, rank()
OVER ( partition by subjects order by mark desc )
AS 'rank' FROM result;
Output:
English Ankita 90 2
English Pratibha 70 3
Maths Swarna 85 2
Maths Ankita 65 3
Science Ankita 80 1
Science Pratibha 80 1
Science Swarna 50 3
previous rank + no of peers (duplicates)
Explanation-
It’s output is similar to dense_rank() function.
Except, that for Science subject in case of a tie between Ankita and Pratibha, the next rank value is
incremented by 2 i.e 3 for Swarna.
3. percent_rank() function-
SELECT subjects, s_name, mark, percent_rank()
OVER ( partition by subjects order by mark )
AS 'percent_rank' FROM result;
Output:
English Pratibha 70 0
Maths Ankita 65 0
Science Swarna 50 0
Englis Prati
h bha 70 0 2 0
Englis Ankit
h a 90 1 2 0.5
Englis Swar 10
h na 0 2 2 1
Math Ankit
s a 65 0 2 0
Math Swar
s na 85 1 2 0.5
Math Prati 10
s bha 0 2 2 1
Scien Swar
ce na 50 0 2 0
Scien Ankit
ce a 80 1 2 0.5
Scien Prati
ce bha 80 1 2 0.5
RDBMS:
Relational DBMS owes its foundation to the fact that the values of each table are related to others. It
has the capability to handle larger magnitudes of data and simulate queries easily.
Relational Database Management Systems maintains data integrity by simulating the following features:
Entity Integrity: No two records of the database table can be completely duplicate.
Referential Integrity: Only the rows of those tables can be deleted which are not used by other
tables. Otherwise, it may lead to data inconsistency.
User-defined Integrity: Rules defined by the users based on confidentiality and access.
Domain integrity: The columns of the database tables are enclosed within some structured
limits, based on default values, type of data or ranges.
Characteristics:
Data must be stored in tabular form in DB file, that is it should be organized in the form of rows
and columns.
Each row of table is called record/tuple . Number of such records is known as the cardinality of
the table
Each column of the table is called an attribute/field. Number of such columns is called the arity
of the table.
Number two records of the DB table can be same. Data duplicity is therefore avoided by using a
candidate key. Candidate Key is a minimum set of attributes required to identify the set of records
uniquely.
Tables are related to each other with the help of foreign keys.
Database tables also allow NULL values, that is if the values of any of the element of the table
are not filled or are missing, it becomes a NULL value, which is not equivalent to zero.
Example:
The following table STUDENT consists of three columns Roll Number, Name, Section and four
records of students 1, 2, 3 and 4 respectively. The records can’t be completely same, the Roll
Number acts as a candidate key which separates records.
1 Anita A
2 Mark B
3 Ish A
4 Toby C
Advantages:
Easy to manage: Each table can be independently manipulated without affecting others.
Security: It is more secure consisting of multiple levels of security. Access of data shared can be
limited.
Flexible: Updation of data can be done at a single point without making amendments in multiple
files. Databases can easily be extended to incorporate more records, thus providing greater scalability.
Also, facilitates easy application of SQL queries.
Users: RDBMS supports client-side architecture storing multiple users together.
Facilitates storage and retrieval of large amount of data.
Easy Data Handling:
Data fetching is faster because of relational architecture.
Data redundancy or duplicity is avoided due to keys, indexes, and normalization
principles.
Data consistency is ensured because RDBMS is based on ACID properties for data
transactions (Atomicity Consistency Isolation Durability).
Fault Tolerance: Replication of databases provides simultaneous access and helps the system
recover in case of disasters, such as power failures or sudden shutdowns
Disadvantages
High Cost and Extensive Hardware and Software Support: Huge costs and setups are required to
make these systems functional.
Scalability: In case of addition of more data, servers along with additional power and memory
are required.
Complexity: Voluminous data creates complexity in understanding of relations and may lower
down the performance.
Structured Limits: The fields or columns of a relational database system is enclosed within
various limits, which may lead to loss of data
Introduction to NoSQL:
NoSQL databases (aka "not only SQL") are non tabular, and store data differently than relational tables.
NoSQL databases come in a variety of types based on their data model. The main types are document,
key-value, wide-column, and graph. They provide flexible schemas and scale easily with large amounts
of data and high user loads.
NoSQL databases can store relationship data—they just store it differently than relational databases do.
In fact, when compared with SQL databases, many find modeling relationship data in NoSQL databases
to be easier than in SQL databases, because related data doesn’t have to be split between tables.
NoSQL data models allow related data to be nested within a single data structure.
As storage costs rapidly decreased, the amount of data applications needed to store and query
increased. This data came in all shapes and sizes—structured, semistructured, and polymorphic—and
defining the schema in advance became nearly impossible. NoSQL databases allow developers to store
huge amounts of unstructured data, giving them a lot of flexibility.
Over time, four major types of NoSQL databases emerged: document databases, key-value databases,
wide-column stores, and graph databases.
Document databases store data in documents similar to JSON (JavaScript Object Notation)
objects. Each document contains pairs of fields and values. The values can typically be a variety
of types including things like strings, numbers, booleans, arrays, or objects, and their structures
typically align with objects developers are working with in code. Because of their variety of field
value types and powerful query languages, document databases are great for a wide variety of
use cases and can be used as a general purpose database. They can horizontally scale-out to
accomodate large data volumes. MongoDB is consistently ranked as the world’s most popular
NoSQL database according to DB-engines and is an example of a document database. For more
on document databases, visit What is a Document Database?
Key-value databases are a simpler type of database where each item contains keys and values. A
value can typically only be retrieved by referencing its key, so learning how to query for a
specific key-value pair is typically simple. Key-value databases are great for use cases where you
need to store large amounts of data but you don’t need to perform complex queries to retrieve
it. Common use cases include storing user preferences or caching. Redis and DynamoDB are
popular key-value databases.
Wide-column stores store data in tables, rows, and dynamic columns. Wide-column stores
provide a lot of flexibility over relational databases because each row is not required to have the
same columns. Many consider wide-column stores to be two-dimensional key-value databases.
Wide-column stores are great for when you need to store large amounts of data and you can
predict what your query patterns will be. Wide-column stores are commonly used for storing
Internet of Things data and user profile data. Cassandra and HBase are two of the most popular
wide-column stores.
Graph databases store data in nodes and edges. Nodes typically store information about people,
places, and things while edges store information about the relationships between the nodes.
Graph databases excel in use cases where you need to traverse relationships to look for patterns
such as social networks, fraud detection, and recommendation engines. Neo4j and JanusGraph
are examples of graph databases.
Last name :: first name :: middle initial :: address fields :: email address :: phone number
Last name :: date of birth :: account number :: customer years :: communication preferences
The NoSQL Case. In the section Types of NoSQL Databases above, there were four types described, and
each has its own data model.
Each type of NoSQL database would be designed with a specific customer situation in mind, and there
would be technical reasons for how each kind of database would be organized. The simplest type to
describe is the document database, in which it would be natural to combine both the basic information
and the customer information in one JSON document. In this case, each of the SQL column attributes
would be fields and the details of a customer’s record would be the data values associated with each
field.
For example: Last_name: "Jones", First_name: "Mary", Middle_initial: "S", etc
Advantages:
There are many advantages of working with NoSQL databases such as MongoDB and Cassandra. The
main advantages are high scalability and high availability.
Disadvantages of NoSQL:
1. Narrow focus –
NoSQL databases have very narrow focus as it is mainly designed for storage but it provides very little
functionality. Relational databases are a better choice in the field of Transaction Management than
NoSQL.
2. Open-source –
NoSQL is open-source database. There is no reliable standard for NoSQL yet. In other words two
database systems are likely to be unequal.
3. Management challenge –
The purpose of big data tools is to make management of a large amount of data as simple as possible.
But it is not so easy. Data management in NoSQL is much more complex than a relational database.
NoSQL, in particular, has a reputation for being challenging to install and even more hectic to manage
on a daily basis.
4. GUI is not available –
GUI mode tools to access the database is not flexibly available in the market.
5. Backup –
Backup is a great weak point for some NoSQL databases like MongoDB. MongoDB has no approach for
the backup of data in a consistent manner.
6. Large document size –
Some database systems like MongoDB and CouchDB store data in JSON format. Which means that
documents are quite large (BigData, network bandwidth, speed), and having descriptive key names
actually hurts, since they increase the document size.