(Unit 3) Introduction To SQL: SQL (Structured Query Language)
(Unit 3) Introduction To SQL: SQL (Structured Query Language)
Introduction
SQL (Structured Query Language)
● SQL is a language to specify queries in structured
manner.
○ Structured means relational data.
○ SQL is a language to specify queries in a
relational database.
● SQL (Structured Query Language) is a computer
language for storing, manipulating, and retrieving
● data stored in relational databases. SQL allows
users to communicate with Relational Databases
and retrieve data from their tables
● SQL is the standard language for RDBMS.
○ All Relational Database Management Systems
(RDBMS) like "MySQL, MS Access, Oracle,
1
SQL Sub-languages
SQL Rules
6
1. CREATE
Creating a DATABASE:
Syntax:
Example:
Note:
SHOW databases;
SHOW tables;
Syntax
USE database_name;
Example:
9
USE my_db;
SHOW tables;
Note:
Syntax:
DESC table_name;
Example:
DESC Emp;
SQL Constraints
SQL Constraints:
2. ALTER
14
Syntax:
15
Example:
Syntax:
Example:
Syntax:
Example:
3. DROP
This command will destroy the table structure and the data
stored in it.
Syntax:
Example:
Syntax:
Example:
4. TRUNCATE
Syntax:
Example:
18
5. RENAME
Syntax:
Example:
WHERE CLAUSE
Syntax:
FROM table_name(s)
WHERE condition;
from r₁,r2,.............rn
where P
A represent attributes
22
r represent relations
SQL Operators
+ [Addition]
- [Subtraction]
/ [Division]
* [Multiplication]
% [Modulus]
Example
Example:
WHERE Salary>2000;
Example:
SELECT
FROM Emp
2. INSERT
26
3. UPDATE
Syntax
Example: UPDATE
UPDATE Emp
SET Address='Chennai'
WHERE Emp_ID=3;
28
To Check:
4. DELETE
Syntax:
WHERE Address='Pune';
29