SQL vs NoSQL

 

SQL vs NoSQL


Title: Comparative Study of SQL and NoSQL Databases


1. Aim

To study and compare SQL (Relational) and NoSQL (Non-relational) databases based on structure, data models, query languages, scalability, consistency, and use-cases.


2. Objectives

By the end of the experiment, the student will be able to:

  • Understand the fundamental differences between SQL and NoSQL databases.

  • Identify different types of NoSQL databases.

  • Write basic queries in SQL and NoSQL.

  • Analyze the ACID and BASE properties.

  • Understand appropriate use-cases for both database models.


3. Theory

3.1 What is SQL?

SQL (Structured Query Language) is used to manage relational databases that store data in tables.
It uses a fixed schema and supports relationships using keys.

Examples of SQL Databases:

  • MySQL

  • PostgreSQL

  • Oracle

  • Microsoft SQL Server

ACID properties ensure high reliability.


3.2 What is NoSQL?

NoSQL stands for Not Only SQL. It is used for storing unstructured, semi-structured, or distributed data.

NoSQL databases are schema-less and scale horizontally.

Examples of NoSQL Databases:

  • MongoDB (Document)

  • Redis (Key-Value)

  • Cassandra (Column Store)

  • Neo4j (Graph)

Uses BASE properties and supports massive real-time data.


3.3 Types of NoSQL Databases

TypeDescriptionExample
Document Store    JSON-like documents    MongoDB
Key-Value Store    Key → value pairs    Redis
Column-Family Store    Columns inside families    Cassandra
Graph Database    Nodes and relationships    Neo4j

3.4 ACID vs BASE

ACID (SQL)    BASE (NoSQL)
Atomicity        Basically Available
Consistency        Soft State
Isolation        Eventual Consistency
Durability            

4. SQL vs NoSQL – Comparison Table

FeatureSQLNoSQL
Data Model            Tables    Documents, Key-values, Graphs
Schema            Fixed    Flexible
Query Language            SQL    No standard
Scalability            Vertical    Horizontal
Consistency            Strong    Eventual
Best for            Complex transactions    Big Data, real-time apps

5. Procedure

Step 1: Install MySQL (SQL Database)

Start MySQL server and open MySQL Shell.

Step 2: Install MongoDB (NoSQL Database)

Start MongoDB service and open mongo shell.

Step 3: Perform SQL Operations

Create a table, insert data, and run a query.

Step 4: Perform NoSQL Operations

Insert a document, retrieve it, and observe the structure.

Step 5: Record differences based on output.


6. SQL Commands (MySQL)

✔ Create a table

CREATE TABLE Students ( id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(100), age INT );

✔ Insert values

INSERT INTO Students (name, age) VALUES ('Alice', 21), ('Bob', 22);

✔ Select data

SELECT * FROM Students;

7. NoSQL Commands (MongoDB)

✔ Insert document

db.students.insertOne({ name: "Alice", age: 21, subjects: ["Math", "Science"] });

✔ Retrieve document

db.students.find();

8. Expected Output

SQL Output

+----+-------+------+ | id | name | age | +----+-------+------+ | 1 | Alice | 21 | | 2 | Bob | 22 | +----+-------+------+

NoSQL Output

{ "_id" : ObjectId("67f4a234..."), "name" : "Alice", "age" : 21, "subjects" : ["Math", "Science"] }

9. Applications

✔ SQL Applications

  • Banking

  • ERP systems

  • College administration

  • Inventory systems

✔ NoSQL Applications

  • Social media platforms

  • Big Data analytics

  • IoT applications

  • Real-time systems (chat apps, gaming)


10. Result

The differences between SQL and NoSQL databases were studied.
SQL was observed to follow a structured relational model, whereas NoSQL stores data in a flexible and scalable format. Both are useful for different application needs.



Comments

Popular posts from this blog

Database Management Systems DBMS Lab PCCSL408 Semester 4 KTU CS 2024 Scheme

DBMS Lab PCCSL408 2024 Scheme and Syllabus

Design a Database Schema for an Application Using ER Diagram from Problem Description