SlideShare a Scribd company logo
Faculty of Engineering and Technology
Parul Institute of Technology
Department of Computer Science & Engineering
Course: B.Tech – CSE
Subject: Database Management System
Unit 2
SQL
• DDL : Data Definition Language
• DQL : Data Query Language
• DML : Data Manipulation Language
• DCL : Data Control Language
• WHERE and LIKE
• Aggregate Functions
• Logical Operators: AND, OR
• BETWEEN, IN, NOT IN
• UNION, INTERSECT, MINUS
• Date Functions
• Character Functions
• Arithmetic Functions
:Overview:
DDL : Data Definition Language
• DDL is a set of SQL commands used to create, modify and
delete database structures but not data.
• List of DDL Commands:
1. CREATE : It is used to create a new table in database.
2. ALTER : It is used to change the structure or definition of a
created table. We can add, remove or change the
particular column name using ALTER. We can change table
name also.
CREATE Command
• Syntax:
CREATE TABLE table_name
(column1_name data type for column1,
column2_name data type for column2,
…
columnN_name data type for column N);
• Example:
CREATE TABLE student
(Enrollment Number int,
Name varchar,
Contact Number varchar,
City varchar);
Output: This will create a table having
four columns.
ALTER Command for adding column
• Syntax:
ALTER TABLE table_name
ADD
column1_name data type for column1,
column2_name data type for column2,
…
columnN_name data type for columnN ;
• Example:
ALTER TABLE Student
ADD
Email ID varchar;
Output: This will add a new column
named ‘Email ID’ into created table
‘Student’. Now this table contains five
columns.
ALTER Command for deleting column
• Syntax:
ALTER TABLE table_name
DROP
column1_name data type for column1,
column2_name data type for column2,
…
columnN_name data type for columnN ;
• Example:
ALTER TABLE Student
DROP
Email ID varchar;
Output: This will remove a new column
named ‘Email ID’ from created table
‘Student’. Now this table contains four
columns.
ALTER Command for renaming column
• Syntax:
ALTER TABLE table_name
RENAME COLUMN existing name TO new
name;
• Example:
ALTER TABLE Student
RENAME COLUMN Enrollment Number TO
EnNo;
Output: This will rename a new column
named ‘Enrollment Number’. New name
of this particular name will be ‘EnNO’.
ALTER Command for renaming table
• Syntax:
ALTER TABLE table_name
RENAME new name of existing table;
• Example:
ALTER TABLE Student
RENAME Student1;
Output: This will rename existing table as
‘Student1’.
DQL : Data Query Language
• DQL is a SQL command used to fetch required data from the
database.
• SELECT is a DQL command.
SELECT Command for fetching all columns
• Syntax:
SELECT * FROM table_name;
• Example:
SELECT * FROM Student;
Output: This will show entire Student
table.
SELECT Command for fetching selected columns
• Syntax:
SELECT
column_name 1,
column_name 2,
…
column_name n
FROM table_name;
• Example:
SELECT Name, City FROM Student;
Output: This will show only two columns
of Student table.
DML : Data Manipulation Language
• DML is a set of SQL commands used to manipulate data.
• List of DML Commands:
1. INSERT : It is used to insert values into a created table in
database.
2. UPDATE : It is used to change the values in a created table.
3. DELETE : It is used to remove the records or values from
the table.
INSERT Command
• Syntax:
INSERT INTO table_name VALUES
(value 1, value 2, … value N);
• Example:
INSERT INTO Student VALUES
(1, ‘Aakash’,’Shah’,
20,’aakashshah@gmail.com’),
(2, ‘Sagar’,’Patel’,
21,’sagarpatel@gmail.com’);
Output: This will insert two rows into the
created Student table.
UPDATE Command
• Syntax:
UPDATE table_name
SET
column1_name=value1,
column2_name=value2,
…
columnn_name=valuen
WHERE condition;
• Example:
UPDATE Student
SET
City=‘Vadodara’
WHERE Enrollment Number=1;
Output: This will update city’s name
‘Vadodara’ for the particular record
having Enrollment Number 1.
DELETE Command
• Syntax:
DELETE FROM table_name
WHERE condition;
• Example:
DELETE FROM Student
WHERE Enrollment Number=1;
Output: This will delete the particular row
having record having Enrollment Number
1.
DCL : Data Control Language
• DCL is a set of SQL commands used to control the access
data stored in a database.
• List of DML Commands:
1. GRANT :
2. REVOKE:
How to create a User?
• Syntax:
CREATE USER user_name
WITH PASSWORD ‘password_value’ | VALID UNTIL ‘expiration’;
• Examples:
CREATE USER abc
WITH PASSWORD ‘abc1234’ | VALID UNTIL ‘Jan 1, 2020’;
CREATE USER def
WITH PASSWORD ‘def1234’ | VALID UNTIL ‘infinity’;
How to delete a User?
• Syntax:
DROP USER user_name;
• Example:
DROP USER abc;
• Syntax:
ALTER USER user_name TO new_name;
• Examples:
ALTER USER abc TO abc1;
How to rename a User?
GRANT
• Syntax:
GRANT privileges ON table_name TO user;
• Examples:
GRANT SELECT, INSERT, UPDATE, DELETE ON Student TO abc;
User “abc” can perform select, insert, update and delete on the table “Student”.
GRANT ALL ON Student TO def;
User “def” can perform all operations on the table “Student”.
GRANT SELECT ON Student TO PUBLIC;
Any user can perform only select operations on the table “Student”.
REVOKE
• Syntax:
REVOKE privileges ON table_name FROM user;
• Examples:
REVOKE ALL ON Student FROM abc;
Permissions are taken back from user “abc”.
WHERE
• The WHERE predicate is used for filter the records.
• It is used to extract only those records that fulfil a specified
condition.
• Syntax:
SELECT
column1_name, column2_name, … columnN_name
FROM table_name
WHERE condition;
• Examples:
1. SELECT First_Name FROM student WHERE age<20;
2. SELECT First_Name, Last_Name FROM student WHERE
age<20;
3. SELECT First_Name, Last_Name FROM student WHERE
city=‘Baroda’;
WHERE
• The LIKE operator is used in a WHERE predicate to search for a specified pattern
in a column.
• There are two wildcards often used with LIKE: % and _
1. A% means string starts with A. Example: AB or ABC or ABCDE.
2. %A means any string that ends with A. Example: BA or CBA.
3. A%B means string starts with A but ends with B. Example: ACGB or ADB.
4. AB_C means string starts with AB then there is any one character and at last there is C.
5. A_C means string starts with A then there is any one character and at last there is C.
6. A_ means string starts with A then there is any one character at the end.
LIKE
• Syntax:
SELECT
column1_name, column2_name, … columnN_name
FROM table_name
WHERE condition
LIKE pattern;
LIKE
• Examples:
1. SELECT First_Name FROM student WHERE age<20 LIKE ‘P%’;
2. SELECT First_Name FROM student WHERE age>25 LIKE ‘M%’;
3. SELECT First_Name FROM student WHERE age>25 LIKE ‘P%K’;
4. SELECT First_Name FROM student WHERE age>25 LIKE ‘%K’;
5. SELECT First_Name FROM student WHERE age>25 LIKE ‘_A%’;
LIKE
• The aggregate function simply refers to the calculations performed on
a data set to get a single number.
• Some common aggregate functions include:
1. COUNT
2. SUM
3. AVG
4. MIN
5. MAX
Aggregate Functions
Consider the following table. We will perform functions on this table.
COUNT Function
• Syntax:
SELECT COUNT (column_name) FROM table_name WHERE condition LIKE pattern;
• Examples:
1. SELECT COUNT (first_name) FROM customers WHERE age<25;
Output: 2
2. SELECT COUNT (first_name) FROM customers WHERE first_name LIKE ‘J%’;
Output: 2
3. SELECT COUNT (customer_id) FROM customers;
Output: 5
4. SELECT COUNT (customer_id) FROM customers WHERE country= ‘USA’;
Output: 2
SUM Function
• Syntax:
SELECT SUM (column_name) FROM table_name WHERE condition LIKE pattern;
• Examples:
1. SELECT SUM (age) FROM customers WHERE age<25;
Output: 44
2. SELECT SUM (age) FROM customers WHERE first_name LIKE ‘J%’;
Output: 56
3. SELECT SUM (customer_id) FROM customers;
Output: 15
4. SELECT SUM (age) FROM customers WHERE country= ‘USA’;
Output: 53
AVG Function
• Syntax:
SELECT AVG (column_name) FROM table_name WHERE condition LIKE pattern;
• Examples:
1. SELECT AVG (age) FROM customers WHERE age<25;
Output: 25.6
2. SELECT AVG (age) FROM customers WHERE first_name LIKE ‘J%’;
Output: 28
3. SELECT AVG (customer_id) FROM customers;
Output: 3
4. SELECT AVG (age) FROM customers WHERE country= ‘USA’;
Output: 26.5
5. SELECT AVG (age*10) FROM customers WHERE country= ‘USA’;
Output: 265
MIN Function
• Syntax:
SELECT MIN (column_name) FROM table_name WHERE condition LIKE pattern;
• Examples:
1. SELECT MIN (age) FROM customers;
Output: 22
2. SELECT MIN (age) FROM customers WHERE first_name LIKE ‘J%’;
Output: 25
3. SELECT MIN (customer_id) FROM customers;
Output: 1
4. SELECT MIN (age) FROM customers WHERE country= ‘USA’;
Output: 22
MAX Function
• Syntax:
SELECT MAX (column_name) FROM table_name WHERE condition LIKE pattern;
• Examples:
1. SELECT MAX (age) FROM customers;
Output: 28
2. SELECT MAX (age) FROM customers WHERE first_name LIKE ‘J%’;
Output: 31
3. SELECT MAX (customer_id) FROM customers;
Output: 5
4. SELECT MAX (age) FROM customers WHERE country= ‘USA’;
Output: 31
• Logical operators are used along with the different
conditions. AND and OR are logical operators.
Logical Operators
Consider the following table. We will perform functions on this table.
• Examples:
1. SELECT * FROM customers WHERE age=22 AND
first_name=‘David’;
2. SELECT * FROM customers WHERE age=22 OR
first_name=‘David’;
3. SELECT * FROM customers WHERE country=‘UK’ AND
(age=22 OR first_name=‘David’);
Logical Operators
BETWEEN
• The SQL BETWEEN condition allows you to easily test if an expression is within a range of inclusive values.
• The values can be text, date, or numbers. It can be used in a SELECT, INSERT, UPDATE, or DELETE
statement.
• Syntax:
SELECT
column1_name, column2_name, … columnN_name
FROM table_name
WHERE condition
BETWEEN value1 AND value2;
• It will return the records where the expression is within the range of value1 and value2.
BETWEEN
• Example 1:
SELECT * FROM customers
WHERE age
BETWEEN 25 AND 30;
• Example 2:
SELECT * FROM customers
WHERE age
NOT BETWEEN 25 AND 30;
IN and NOT IN
• IN operator allows you to easily test if the expression matches any value in the list of values.
• It is used to remove the need for multiple OR conditions in SELECT, INSERT, UPDATE, or DELETE.
• You can also use NOT IN to exclude the rows in your list.
• Syntax:
SELECT
column1_name, column2_name, … columnN_name
FROM table_name
WHERE condition
IN (value1, value2, …, value n);
IN and NOT IN
• Example 1:
SELECT * FROM customers
WHERE age IN (22,28);
• Example 2:
SELECT * FROM customers
WHERE age NOT IN (22,28);
UNION
Consider the following tables. We will perform union operation on these tables.
UNION
SELECT Name FROM Teachers
UNION
SELECT Name FROM Students;
Output
UNION
SELECT * FROM Teachers
UNION
SELECT * FROM Students;
Output
INTERSECTION
Consider the following tables. We will perform intersection operation on these tables.
INTERSECTION
SELECT customer_id FROM Customers
INTERSECT
SELECT customer_id FROM Orders; Output
MINUS
Consider the following tables. We will perform minus operation on these tables.
MINUS
SELECT customer_id FROM Customers
MINUS
SELECT customer_id FROM Orders; Output
1. SELECT Current_date;
This command will show date in form of YYYY-MM-DD.
2. SELECT Current_time;
This command will show current time.
3. SELECT Current_timestamp;
This command will show current time and date.
Date Functions
1. Select lower('ABC’);
2. Select upper('abc’);
3. Select lower(upper('abc'));
4. Select upper(lower('ABC’));
5. Select length(‘Hello Good Morning’);
Character Functions
Output
Arithmetic Functions
Consider the following table for arithmetic operations.
Select customer_id, first_name, age+10 AS "age+10" from Customers;
Addition
Select customer_id, first_name, age-10 AS "age-10" from Customers;
Subtraction
Select customer_id, first_name, age*10 AS "age*10" from Customers;
Multiplication
Select customer_id, first_name, age/10 AS "age/10" from Customers;
Division
Select customer_id, first_name, age%10 AS "age%10" from Customers;
Modulus
4. Round function:
Select ROUND (213.456, 2);
Output => 213.46
Select ROUND (213.456, 1);
Output => 213.5
Some other functions
1. PI function:
Select PI ();
Output => 3.141592653589793
2. SQRT function:
Select SQRT (100);
Output => 10
3. SQUARE function:
Select SQUARE (5);
Output => 25
5. CEIL function:
Select ceil(23.34);
Output => 24
6. FLOOR function:
Select floor(23.34);
Output => 23
7. POWER function:
Select power(2,3);
Output => 8

More Related Content

PDF
SQL 🌟🌟🔥.pdf
PDF
1670595076250.pdf
PDF
Cheat sheet SQL commands with examples and easy understanding
PDF
SQL learning notes and all code.pdf
PPT
Mysql 120831075600-phpapp01
PPT
Sql Commands_Dr.R.Shalini.ppt
PDF
SQL for data scientist And data analysist Advanced
PPT
MY SQL
SQL 🌟🌟🔥.pdf
1670595076250.pdf
Cheat sheet SQL commands with examples and easy understanding
SQL learning notes and all code.pdf
Mysql 120831075600-phpapp01
Sql Commands_Dr.R.Shalini.ppt
SQL for data scientist And data analysist Advanced
MY SQL

Similar to rdbms parul university oracle dbms bca mca (20)

PPTX
Its about a sql topic for basic structured query language
PDF
SQL-Notes.pdf mba students database note
PPTX
SQL Query
DOCX
SQL report
PPTX
Introduction to sql new
PDF
PPTX
Avinash database
PPTX
SAMPLE QUESTION PAPER (THEORY) CLASS: XII SESSION: 2024-25 COMPUTER SCIENCE...
PPTX
SQL.pptx SAMPLE QUESTION PAPER (THEORY) CLASS: XII SESSION: 2024-25 COMPUTE...
PPTX
PDF
STRUCTURED QUERY LANGUAGE
PDF
sql notes Provideby AGN HUB Tech & It Solutions
PPTX
PPT
Db1 lecture4
PPTX
Structure Query Language Advance Training
PPTX
My SQL.pptx
PPTX
Database COMPLETE
PPTX
PDF
Chapter8 my sql revision tour
PPT
INTRODUCTION TO SQL QUERIES REALTED BRIEF
Its about a sql topic for basic structured query language
SQL-Notes.pdf mba students database note
SQL Query
SQL report
Introduction to sql new
Avinash database
SAMPLE QUESTION PAPER (THEORY) CLASS: XII SESSION: 2024-25 COMPUTER SCIENCE...
SQL.pptx SAMPLE QUESTION PAPER (THEORY) CLASS: XII SESSION: 2024-25 COMPUTE...
STRUCTURED QUERY LANGUAGE
sql notes Provideby AGN HUB Tech & It Solutions
Db1 lecture4
Structure Query Language Advance Training
My SQL.pptx
Database COMPLETE
Chapter8 my sql revision tour
INTRODUCTION TO SQL QUERIES REALTED BRIEF
Ad

More from VaibhavSrivastav52 (18)

PPTX
PPT-3.pptxppppppppppppppppppppppppppppppppppppppppp
PPTX
PPT-1.pptxpppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp
PPTX
PPT-2.pptxpppppppppppppppppppppppppppppppppppp
PPTX
S-VYASA STQA-1.pptx00000000000000000000000000000000
PPTX
S-VYASA dbms111111111111111111111111111111111111111
PPTX
rdbms1-191014080818000000000000000000000000000000000
PPTX
rdbms3, dbms,dbms,rdbmssssssssssssssssssssssssssssssssss
PPTX
Ch09-4-modelBased.pptxhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
PPTX
Ch07-3-sourceCode.pptxhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
PPTX
Ch09-5-inputs.pptx ccccccccccccccccccccccccccccccccccccccccc
PPTX
advanced database management system by uni
PPTX
advanced database management system by uni
PPTX
python_module_4....................................
PPTX
python_module_3....................................
PPTX
python_module_........................................
PPTX
python_module_.................................................................
PPTX
RDBMS PARUL UNIVERSITY VADODARA BTECH CSE
PPTX
dbms ppt parul university dbms course for
PPT-3.pptxppppppppppppppppppppppppppppppppppppppppp
PPT-1.pptxpppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp
PPT-2.pptxpppppppppppppppppppppppppppppppppppp
S-VYASA STQA-1.pptx00000000000000000000000000000000
S-VYASA dbms111111111111111111111111111111111111111
rdbms1-191014080818000000000000000000000000000000000
rdbms3, dbms,dbms,rdbmssssssssssssssssssssssssssssssssss
Ch09-4-modelBased.pptxhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
Ch07-3-sourceCode.pptxhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
Ch09-5-inputs.pptx ccccccccccccccccccccccccccccccccccccccccc
advanced database management system by uni
advanced database management system by uni
python_module_4....................................
python_module_3....................................
python_module_........................................
python_module_.................................................................
RDBMS PARUL UNIVERSITY VADODARA BTECH CSE
dbms ppt parul university dbms course for
Ad

Recently uploaded (20)

PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPT
Teaching material agriculture food technology
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Cloud computing and distributed systems.
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Dropbox Q2 2025 Financial Results & Investor Presentation
Mobile App Security Testing_ A Comprehensive Guide.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Digital-Transformation-Roadmap-for-Companies.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Reach Out and Touch Someone: Haptics and Empathic Computing
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Teaching material agriculture food technology
MIND Revenue Release Quarter 2 2025 Press Release
MYSQL Presentation for SQL database connectivity
Review of recent advances in non-invasive hemoglobin estimation
Network Security Unit 5.pdf for BCA BBA.
Cloud computing and distributed systems.
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf

rdbms parul university oracle dbms bca mca

  • 1. Faculty of Engineering and Technology Parul Institute of Technology Department of Computer Science & Engineering Course: B.Tech – CSE Subject: Database Management System
  • 3. • DDL : Data Definition Language • DQL : Data Query Language • DML : Data Manipulation Language • DCL : Data Control Language • WHERE and LIKE • Aggregate Functions • Logical Operators: AND, OR • BETWEEN, IN, NOT IN • UNION, INTERSECT, MINUS • Date Functions • Character Functions • Arithmetic Functions :Overview:
  • 4. DDL : Data Definition Language • DDL is a set of SQL commands used to create, modify and delete database structures but not data. • List of DDL Commands: 1. CREATE : It is used to create a new table in database. 2. ALTER : It is used to change the structure or definition of a created table. We can add, remove or change the particular column name using ALTER. We can change table name also.
  • 5. CREATE Command • Syntax: CREATE TABLE table_name (column1_name data type for column1, column2_name data type for column2, … columnN_name data type for column N); • Example: CREATE TABLE student (Enrollment Number int, Name varchar, Contact Number varchar, City varchar); Output: This will create a table having four columns.
  • 6. ALTER Command for adding column • Syntax: ALTER TABLE table_name ADD column1_name data type for column1, column2_name data type for column2, … columnN_name data type for columnN ; • Example: ALTER TABLE Student ADD Email ID varchar; Output: This will add a new column named ‘Email ID’ into created table ‘Student’. Now this table contains five columns.
  • 7. ALTER Command for deleting column • Syntax: ALTER TABLE table_name DROP column1_name data type for column1, column2_name data type for column2, … columnN_name data type for columnN ; • Example: ALTER TABLE Student DROP Email ID varchar; Output: This will remove a new column named ‘Email ID’ from created table ‘Student’. Now this table contains four columns.
  • 8. ALTER Command for renaming column • Syntax: ALTER TABLE table_name RENAME COLUMN existing name TO new name; • Example: ALTER TABLE Student RENAME COLUMN Enrollment Number TO EnNo; Output: This will rename a new column named ‘Enrollment Number’. New name of this particular name will be ‘EnNO’.
  • 9. ALTER Command for renaming table • Syntax: ALTER TABLE table_name RENAME new name of existing table; • Example: ALTER TABLE Student RENAME Student1; Output: This will rename existing table as ‘Student1’.
  • 10. DQL : Data Query Language • DQL is a SQL command used to fetch required data from the database. • SELECT is a DQL command.
  • 11. SELECT Command for fetching all columns • Syntax: SELECT * FROM table_name; • Example: SELECT * FROM Student; Output: This will show entire Student table.
  • 12. SELECT Command for fetching selected columns • Syntax: SELECT column_name 1, column_name 2, … column_name n FROM table_name; • Example: SELECT Name, City FROM Student; Output: This will show only two columns of Student table.
  • 13. DML : Data Manipulation Language • DML is a set of SQL commands used to manipulate data. • List of DML Commands: 1. INSERT : It is used to insert values into a created table in database. 2. UPDATE : It is used to change the values in a created table. 3. DELETE : It is used to remove the records or values from the table.
  • 14. INSERT Command • Syntax: INSERT INTO table_name VALUES (value 1, value 2, … value N); • Example: INSERT INTO Student VALUES (1, ‘Aakash’,’Shah’, 20,’aakashshah@gmail.com’), (2, ‘Sagar’,’Patel’, 21,’sagarpatel@gmail.com’); Output: This will insert two rows into the created Student table.
  • 15. UPDATE Command • Syntax: UPDATE table_name SET column1_name=value1, column2_name=value2, … columnn_name=valuen WHERE condition; • Example: UPDATE Student SET City=‘Vadodara’ WHERE Enrollment Number=1; Output: This will update city’s name ‘Vadodara’ for the particular record having Enrollment Number 1.
  • 16. DELETE Command • Syntax: DELETE FROM table_name WHERE condition; • Example: DELETE FROM Student WHERE Enrollment Number=1; Output: This will delete the particular row having record having Enrollment Number 1.
  • 17. DCL : Data Control Language • DCL is a set of SQL commands used to control the access data stored in a database. • List of DML Commands: 1. GRANT : 2. REVOKE:
  • 18. How to create a User? • Syntax: CREATE USER user_name WITH PASSWORD ‘password_value’ | VALID UNTIL ‘expiration’; • Examples: CREATE USER abc WITH PASSWORD ‘abc1234’ | VALID UNTIL ‘Jan 1, 2020’; CREATE USER def WITH PASSWORD ‘def1234’ | VALID UNTIL ‘infinity’;
  • 19. How to delete a User? • Syntax: DROP USER user_name; • Example: DROP USER abc;
  • 20. • Syntax: ALTER USER user_name TO new_name; • Examples: ALTER USER abc TO abc1; How to rename a User?
  • 21. GRANT • Syntax: GRANT privileges ON table_name TO user; • Examples: GRANT SELECT, INSERT, UPDATE, DELETE ON Student TO abc; User “abc” can perform select, insert, update and delete on the table “Student”. GRANT ALL ON Student TO def; User “def” can perform all operations on the table “Student”. GRANT SELECT ON Student TO PUBLIC; Any user can perform only select operations on the table “Student”.
  • 22. REVOKE • Syntax: REVOKE privileges ON table_name FROM user; • Examples: REVOKE ALL ON Student FROM abc; Permissions are taken back from user “abc”.
  • 23. WHERE • The WHERE predicate is used for filter the records. • It is used to extract only those records that fulfil a specified condition. • Syntax: SELECT column1_name, column2_name, … columnN_name FROM table_name WHERE condition;
  • 24. • Examples: 1. SELECT First_Name FROM student WHERE age<20; 2. SELECT First_Name, Last_Name FROM student WHERE age<20; 3. SELECT First_Name, Last_Name FROM student WHERE city=‘Baroda’; WHERE
  • 25. • The LIKE operator is used in a WHERE predicate to search for a specified pattern in a column. • There are two wildcards often used with LIKE: % and _ 1. A% means string starts with A. Example: AB or ABC or ABCDE. 2. %A means any string that ends with A. Example: BA or CBA. 3. A%B means string starts with A but ends with B. Example: ACGB or ADB. 4. AB_C means string starts with AB then there is any one character and at last there is C. 5. A_C means string starts with A then there is any one character and at last there is C. 6. A_ means string starts with A then there is any one character at the end. LIKE
  • 26. • Syntax: SELECT column1_name, column2_name, … columnN_name FROM table_name WHERE condition LIKE pattern; LIKE
  • 27. • Examples: 1. SELECT First_Name FROM student WHERE age<20 LIKE ‘P%’; 2. SELECT First_Name FROM student WHERE age>25 LIKE ‘M%’; 3. SELECT First_Name FROM student WHERE age>25 LIKE ‘P%K’; 4. SELECT First_Name FROM student WHERE age>25 LIKE ‘%K’; 5. SELECT First_Name FROM student WHERE age>25 LIKE ‘_A%’; LIKE
  • 28. • The aggregate function simply refers to the calculations performed on a data set to get a single number. • Some common aggregate functions include: 1. COUNT 2. SUM 3. AVG 4. MIN 5. MAX Aggregate Functions Consider the following table. We will perform functions on this table.
  • 29. COUNT Function • Syntax: SELECT COUNT (column_name) FROM table_name WHERE condition LIKE pattern; • Examples: 1. SELECT COUNT (first_name) FROM customers WHERE age<25; Output: 2 2. SELECT COUNT (first_name) FROM customers WHERE first_name LIKE ‘J%’; Output: 2 3. SELECT COUNT (customer_id) FROM customers; Output: 5 4. SELECT COUNT (customer_id) FROM customers WHERE country= ‘USA’; Output: 2
  • 30. SUM Function • Syntax: SELECT SUM (column_name) FROM table_name WHERE condition LIKE pattern; • Examples: 1. SELECT SUM (age) FROM customers WHERE age<25; Output: 44 2. SELECT SUM (age) FROM customers WHERE first_name LIKE ‘J%’; Output: 56 3. SELECT SUM (customer_id) FROM customers; Output: 15 4. SELECT SUM (age) FROM customers WHERE country= ‘USA’; Output: 53
  • 31. AVG Function • Syntax: SELECT AVG (column_name) FROM table_name WHERE condition LIKE pattern; • Examples: 1. SELECT AVG (age) FROM customers WHERE age<25; Output: 25.6 2. SELECT AVG (age) FROM customers WHERE first_name LIKE ‘J%’; Output: 28 3. SELECT AVG (customer_id) FROM customers; Output: 3 4. SELECT AVG (age) FROM customers WHERE country= ‘USA’; Output: 26.5 5. SELECT AVG (age*10) FROM customers WHERE country= ‘USA’; Output: 265
  • 32. MIN Function • Syntax: SELECT MIN (column_name) FROM table_name WHERE condition LIKE pattern; • Examples: 1. SELECT MIN (age) FROM customers; Output: 22 2. SELECT MIN (age) FROM customers WHERE first_name LIKE ‘J%’; Output: 25 3. SELECT MIN (customer_id) FROM customers; Output: 1 4. SELECT MIN (age) FROM customers WHERE country= ‘USA’; Output: 22
  • 33. MAX Function • Syntax: SELECT MAX (column_name) FROM table_name WHERE condition LIKE pattern; • Examples: 1. SELECT MAX (age) FROM customers; Output: 28 2. SELECT MAX (age) FROM customers WHERE first_name LIKE ‘J%’; Output: 31 3. SELECT MAX (customer_id) FROM customers; Output: 5 4. SELECT MAX (age) FROM customers WHERE country= ‘USA’; Output: 31
  • 34. • Logical operators are used along with the different conditions. AND and OR are logical operators. Logical Operators Consider the following table. We will perform functions on this table.
  • 35. • Examples: 1. SELECT * FROM customers WHERE age=22 AND first_name=‘David’; 2. SELECT * FROM customers WHERE age=22 OR first_name=‘David’; 3. SELECT * FROM customers WHERE country=‘UK’ AND (age=22 OR first_name=‘David’); Logical Operators
  • 36. BETWEEN • The SQL BETWEEN condition allows you to easily test if an expression is within a range of inclusive values. • The values can be text, date, or numbers. It can be used in a SELECT, INSERT, UPDATE, or DELETE statement. • Syntax: SELECT column1_name, column2_name, … columnN_name FROM table_name WHERE condition BETWEEN value1 AND value2; • It will return the records where the expression is within the range of value1 and value2.
  • 37. BETWEEN • Example 1: SELECT * FROM customers WHERE age BETWEEN 25 AND 30; • Example 2: SELECT * FROM customers WHERE age NOT BETWEEN 25 AND 30;
  • 38. IN and NOT IN • IN operator allows you to easily test if the expression matches any value in the list of values. • It is used to remove the need for multiple OR conditions in SELECT, INSERT, UPDATE, or DELETE. • You can also use NOT IN to exclude the rows in your list. • Syntax: SELECT column1_name, column2_name, … columnN_name FROM table_name WHERE condition IN (value1, value2, …, value n);
  • 39. IN and NOT IN • Example 1: SELECT * FROM customers WHERE age IN (22,28); • Example 2: SELECT * FROM customers WHERE age NOT IN (22,28);
  • 40. UNION Consider the following tables. We will perform union operation on these tables.
  • 41. UNION SELECT Name FROM Teachers UNION SELECT Name FROM Students; Output
  • 42. UNION SELECT * FROM Teachers UNION SELECT * FROM Students; Output
  • 43. INTERSECTION Consider the following tables. We will perform intersection operation on these tables.
  • 44. INTERSECTION SELECT customer_id FROM Customers INTERSECT SELECT customer_id FROM Orders; Output
  • 45. MINUS Consider the following tables. We will perform minus operation on these tables.
  • 46. MINUS SELECT customer_id FROM Customers MINUS SELECT customer_id FROM Orders; Output
  • 47. 1. SELECT Current_date; This command will show date in form of YYYY-MM-DD. 2. SELECT Current_time; This command will show current time. 3. SELECT Current_timestamp; This command will show current time and date. Date Functions
  • 48. 1. Select lower('ABC’); 2. Select upper('abc’); 3. Select lower(upper('abc')); 4. Select upper(lower('ABC’)); 5. Select length(‘Hello Good Morning’); Character Functions Output
  • 49. Arithmetic Functions Consider the following table for arithmetic operations.
  • 50. Select customer_id, first_name, age+10 AS "age+10" from Customers; Addition
  • 51. Select customer_id, first_name, age-10 AS "age-10" from Customers; Subtraction
  • 52. Select customer_id, first_name, age*10 AS "age*10" from Customers; Multiplication
  • 53. Select customer_id, first_name, age/10 AS "age/10" from Customers; Division
  • 54. Select customer_id, first_name, age%10 AS "age%10" from Customers; Modulus
  • 55. 4. Round function: Select ROUND (213.456, 2); Output => 213.46 Select ROUND (213.456, 1); Output => 213.5 Some other functions 1. PI function: Select PI (); Output => 3.141592653589793 2. SQRT function: Select SQRT (100); Output => 10 3. SQUARE function: Select SQUARE (5); Output => 25 5. CEIL function: Select ceil(23.34); Output => 24 6. FLOOR function: Select floor(23.34); Output => 23 7. POWER function: Select power(2,3); Output => 8