Categories

Advertisement
⏱️ 7 min read

What is SQL

N
By NotesMind
Advertisement

Definition (English)

SQL (Structured Query Language) is a standard programming language used to communicate with relational databases.

It allows users to:

  • Store Data
  • Retrieve Data
  • Update Data
  • Delete Data
  • Manage Database

Definition (Hindi)

SQL (Structured Query Language) एक Standard Language है जिसका उपयोग Database से Data को Store, Retrieve, Update, Delete और Manage करने के लिए किया जाता है।


Simple Definition

SQL = Database की भाषा (Language of Database)

जैसे हम इंसानों से बात करने के लिए भाषा का उपयोग करते हैं, वैसे ही Database से बात करने के लिए SQL का उपयोग किया जाता है।


Real-Life Example

Suppose a school has 10,000 students.

Question:

Show all students from CSE Department.

Without SQL:

❌ Search manually

With SQL:


 
SELECT * FROM Student
WHERE Department='CSE';

Result:

Database instantly returns the required students.


Why SQL?

Without SQL

  • Difficult searching
  • Manual work
  • Slow processing
  • Error-prone

With SQL

  • Fast
  • Accurate
  • Secure
  • Easy to learn
  • Standard language

Where is SQL Used?

SQL is used in:

  • Banking Systems
  • Hospitals
  • Schools
  • Colleges
  • Airlines
  • Railway Reservation
  • E-commerce
  • Social Media
  • Government Databases
  • Mobile Apps
  • Web Applications

Popular Databases Using SQL

Database Company
MySQL Oracle
PostgreSQL PostgreSQL Global Development Group
Oracle Database Oracle
Microsoft SQL Server Microsoft
SQLite SQLite Consortium
MariaDB MariaDB Foundation

History of SQL

Year Event
1970 Relational Model proposed by Edgar F. Codd
1974 SQL developed at IBM
1986 SQL became ANSI Standard
1987 SQL became ISO Standard

Features of SQL

  • Easy to Learn

  • Simple Syntax
  • Portable
  • High Performance
  • Secure
  • Standard Language
  • Supports Large Databases
  • Supports Transactions
  • Supports Constraints
  • Supports Multiple Users

Advantages of SQL

✔ Easy data retrieval

✔ Fast processing

✔ Less coding

✔ Secure

✔ Reliable

✔ Standard Language

✔ Supports millions of records


Disadvantages

  • Complex queries can be difficult.

  • Vendor-specific extensions differ.
  • Requires optimization for very large databases.

SQL Architecture


 
          User

            │

            ▼

      SQL Query

            │

            ▼

     Database Engine

            │

            ▼

        Database

SQL Categories

SQL commands are divided into five categories.


 
                 SQL

                  │

      ┌───────────┼────────────┐

      │           │            │

     DDL         DML          DQL

      │

      ├───────────────┐

      │               │

     DCL             TCL

SQL Categories Explained

Category Purpose
DDL Defines database structure
DML Manipulates data
DQL Retrieves data
DCL Controls permissions
TCL Manages transactions

DDL (Data Definition Language)

DDL changes the structure of database objects.

Commands:

  • CREATE
  • ALTER
  • DROP
  • TRUNCATE
  • RENAME

Example:


 
CREATE TABLE Student
(
StudentID INT,
Name VARCHAR(50)
);

DML (Data Manipulation Language)

DML manipulates data.

Commands:

  • INSERT
  • UPDATE
  • DELETE

Example


 
INSERT INTO Student

VALUES(101,'Rahul');

DQL (Data Query Language)

Used to retrieve data.

Command:


 
SELECT

Example


 
SELECT *

FROM Student;

DCL (Data Control Language)

Controls permissions.

Commands:

  • GRANT
  • REVOKE

Example


 
GRANT SELECT

ON Student

TO User1;

TCL (Transaction Control Language)

Manages transactions.

Commands

  • COMMIT
  • ROLLBACK
  • SAVEPOINT

Example

COMMIT;

SQL Data Types

Numeric

  • INT

  • BIGINT
  • SMALLINT
  • DECIMAL
  • FLOAT
  • DOUBLE

Character

  • CHAR
  • VARCHAR
  • TEXT

Date & Time

  • DATE

  • TIME
  • DATETIME
  • TIMESTAMP

Boolean

  • BOOLEAN

SQL Syntax Rules

  • SQL keywords are not case-sensitive.


 
SELECT

Same as


 
select

  • Statements usually end with a semicolon.

 
SELECT * FROM Student;

  • String values use single quotes.

 
'Rahul'

SQL Comments

Single-line:

-- This is a comment

Multi-line:

/*****

This is a comment

*****/

Database Creation

CREATE DATABASE CollegeDB;

Select Database

USE CollegeDB;

(MySQL and SQL Server)


Create Table

CREATE TABLE Student
(
StudentID INT PRIMARY KEY,

Name VARCHAR(50),

Age INT,

Department VARCHAR(30)
);

Table Structure

StudentID Name Age Department
101 Rahul 20 CSE

CRUD Operations

CRUD means:

Create

Read

Update

Delete
Operation SQL Command
Create INSERT
Read SELECT
Update UPDATE
Delete DELETE

SQL Workflow

Create Database

↓

Create Table

↓

Insert Data

↓

Retrieve Data

↓

Update Data

↓

Delete Data

Complete Example

Create Table

CREATE TABLE Employee
(
EmpID INT PRIMARY KEY,

Name VARCHAR(50),

Salary INT
);

Insert Data

INSERT INTO Employee

VALUES

(101,'Rahul',50000),

(102,'Aman',45000);

Retrieve Data

SELECT *

FROM Employee;

Update

UPDATE Employee

SET Salary=55000

WHERE EmpID=101;

Delete

DELETE FROM Employee

WHERE EmpID=102;

 

Advertisement

💬 Leave a Comment & Rating