SlideShare a Scribd company logo
3
Most read
7
Most read
9
Most read
INTRODUCTION TO SQL
RESHMI PRADEEP
index
 What is SQL
 What Can SQL do?
 SQL Commands
 SQL Aggregate Functions
 SQL Joins
What is SQL?
• SQL stands for Structured Query Language
• SQL lets you access and manipulate databases
• SQL became a standard of the American National
Standards Institute (ANSI) in 1986, and of the
International Organization for Standardization (ISO) in
1987
What Can SQL do?
• SQL can execute queries against a database
• SQL can retrieve data from a database
• SQL can insert records in a database
• SQL can update records in a database
• SQL can delete records from a database
• SQL can create new databases
• SQL can create new tables in a database
• SQL can create stored procedures in a database
• SQL can create views in a database
• SQL can set permissions on tables, procedures, and views
SQL Commands
• Types of SQL Commands:
• DDL (Data Definition Language):
• DML (Data Manipulation Language):
• DCL (Data Control Language
• TCL (Transaction Control Language)
Data Definition Language (DDL)
Commands
Data Definition Language, is a subset of SQL (Structured
Query Language) commands used to define and modify the
database structure. These commands are used to create,
alter, and delete database objects like tables, indexes, and
schemas.
1. CREATE: Creates a new table or database.
2. ALTER: Modifies an existing database object.
3. DROP: Deletes an entire table, database, or other objects.
4. TRUNCATE: Removes all records from a table, deleting the
space allocated for the records.
DDL commands play a crucial role in defining the database schema.
The primary DDL commands in SQL include:
• CREATE: This command is used to create a new database object.
For example, creating a new table, a view, or a database.
Syntax for creating a table: CREATE TABLE table_name (column1 datatype,
column2 datatype, ...);
ALTER: This command is used to modify an existing database object,
such as adding, deleting, or modifying columns in an existing table.
Syntax for adding a column in a table: ALTER TABLE table_name ADD
column_name datatype;
Syntax for modifying a column in a table: ALTER TABLE table_name MODIFY
COLUMN column_name datatype;
• TRUNCATE: This command is used to delete
all data from a table, but the structure of
the table remains. It’s a fast way to clear
large data from a table.
Syntax: TRUNCATE TABLE table_name;
• COMMENT: Used to add comments to the
data dictionary.
Syntax: COMMENT ON TABLE table_name IS 'This is a comment.’;
• RENAME: Used to rename an existing
database object.
Data Manipulation Language
(DML)
Data Manipulation Language (DML) is a subset of SQL commands used
for adding (inserting), deleting, and modifying (updating) data in a
database. DML commands are crucial for managing the data within the
tables of a database.
1. SELECT: Retrieves data from the database.
2. INSERT: Adds new data to a table.
3. UPDATE: Modifies existing data within a table.
4. DELETE: Removes data from a table.
INSERT: This command is used to add new rows (records) to a table.
Syntax: INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
UPDATE: This command is used to modify the existing records in a table.
Syntax: UPDATE table_name SET column1 = value1, column2 =
value2, ... WHERE condition;
The WHERE clause specifies which records should be updated. Without it, all
records in the table will be updated.
DELETE: This command is used to remove one or more rows from a table.
Syntax: DELETE FROM table_name WHERE condition;
Like with UPDATE, the WHERE clause specifies which rows should be deleted.
Omitting the WHERE clause will result in all rows being deleted
SELECT: Although often categorized separately, the SELECT command is
sometimes considered part of DML as it is used to retrieve data from the database.
Syntax: SELECT column1, column2, ... FROM table_name WHERE condition;
The SELECT statement is used to query and extract data from a table, which can
then be used for various purposes.
Data Control Language (DCL) Commands in
SQL
Data Control Language (DCL) is a subset of SQL commands used to
control access to data in a database. DCL is crucial for ensuring
security and proper data management, especially in multi-user
database environments.
• GRANT: This command is used to give users access privileges to
the database. These privileges can include the ability to select,
insert, update, delete, and so on, over database objects like tables
and views.
Syntax: GRANT privilege_name ON object_name TO user_name;
For example, GRANT SELECT ON employees TO user123; gives
user123 the permission to read data from the employees table.
• REVOKE: This command is used to remove previously granted access
privileges from a user.
Syntax: REVOKE privilege_name ON object_name FROM user_name;
For example, REVOKE SELECT ON employees FROM user123; would
remove user123‘s permission to read data from the employees table.
Transaction Control Language (TCL)
Transaction Control Language, is a subset of SQL used to manage
database transactions. TCL commands ensure data integrity by allowing
you to control when changes to the database are saved permanently or
rolled back.
COMMIT:The COMMIT command is used to save changes made during
a transaction to the database permanently:
BEGIN;
-- SQL statements
COMMIT;
ROLLBACK:The ROLLBACK command is used to undo changes
made during a transaction:
BEGIN;
-- SQL statements
ROLLBACK;
This example begins a transaction, performs SQL statements, and then rolls
back the changes, restoring the database to its previous state.
SAVEPOINT:The SAVEPOINT command allows you to set a point
within a transaction to which you can later roll back:
BEGIN;
-- SQL statements
SAVEPOINT my_savepoint;
-- More SQL statements
ROLLBACK TO my_savepoint;
This example creates a savepoint and later rolls back to that point,
SQL Aggregate Functions
• MIN() - returns the smallest value within the selected column
Syntax:
SELECT MIN(column_name)
FROM table_name
WHERE condition;
• Example: SELECT MIN(Price)FROM Products;
• MAX() - returns the largest value within the selected column
Syntax:
SELECT MAX(column_name)
FROM table_name
WHERE condition;
• Example: SELECT MAX(Price)FROM Products;
• COUNT() - returns the number of rows in a set
Syntax
SELECT COUNT(column_name)
FROM table_name
WHERE condition;
• Example: SELECT COUNT(*) FROM Products;
• SUM() - returns the total sum of a numerical column
Syntax
SELECT SUM(column_name)
FROM table_name
WHERE condition;
• Example:SELECT SUM(Quantity) FROM OrderDetails;
• AVG() - returns the average value of a numerical column
• Syntax
SELECT AVG(column_name)
FROM table_name
WHERE condition;
Example:SELECT AVG(Price) FROM Products;
SQL Joins
A JOIN clause is used to combine rows from two or more tables, based
on a related column between them.
SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
FROM Orders
INNER JOIN Customers ON Orders.CustomerID=Customers.CustomerID;
Different Types of SQL JOINs
• (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
The SQL SELECT DISTINCT Statement
The SELECT DISTINCT statement is used to return only distinct
(different) values.
Syntax
SELECT DISTINCT column1, column2, ...
FROM table_name;
Example
SQL WHERE Clause
The WHERE clause is used to filter records.
It is used to extract only those records that fulfill a specified condition.
Example
SQL ORDER BY Keyword
The ORDER BY keyword is used to sort the result-set in
ascending or descending order.
Example

More Related Content

Similar to Introduction to database and sql fir beginers (20)

PDF
Structures query language ___PPT (1).pdf
tipurple7989
 
PPTX
SQL.pptx for the begineers and good know
PavithSingh
 
PPTX
Database COMPLETE
Abrar ali
 
PPTX
Introduction to sql new
SANTOSH RATH
 
DOCX
COMPUTERS SQL
Rc Os
 
PPTX
Unit - II.pptx
MrsSavitaKumbhare
 
PPTX
introdution to SQL and SQL functions
farwa waqar
 
PPTX
2..basic queries.pptx
MalaikaRahatQurashi
 
PPTX
SQL-SHORT-NOTES.pptx
PratheeshKumarN
 
PPTX
SQl data base management and design
franckelsania20
 
PDF
sql notes Provideby AGN HUB Tech & It Solutions
mohanagn2244
 
PPTX
Sql basic things
Nishil Jain
 
PDF
Sql smart reference_by_prasad
paddu123
 
PDF
Sql smart reference_by_prasad
paddu123
 
PPT
Sql Commands_Dr.R.Shalini.ppt
DrRShaliniVISTAS
 
PPTX
SQL - DML and DDL Commands
Shrija Madhu
 
PPTX
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
EliasPetros
 
PPT
SQL.ppt
Ranjit273515
 
PPTX
SQL
Rajesh-QA
 
DOC
Adbms
jass12345
 
Structures query language ___PPT (1).pdf
tipurple7989
 
SQL.pptx for the begineers and good know
PavithSingh
 
Database COMPLETE
Abrar ali
 
Introduction to sql new
SANTOSH RATH
 
COMPUTERS SQL
Rc Os
 
Unit - II.pptx
MrsSavitaKumbhare
 
introdution to SQL and SQL functions
farwa waqar
 
2..basic queries.pptx
MalaikaRahatQurashi
 
SQL-SHORT-NOTES.pptx
PratheeshKumarN
 
SQl data base management and design
franckelsania20
 
sql notes Provideby AGN HUB Tech & It Solutions
mohanagn2244
 
Sql basic things
Nishil Jain
 
Sql smart reference_by_prasad
paddu123
 
Sql smart reference_by_prasad
paddu123
 
Sql Commands_Dr.R.Shalini.ppt
DrRShaliniVISTAS
 
SQL - DML and DDL Commands
Shrija Madhu
 
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
EliasPetros
 
SQL.ppt
Ranjit273515
 
Adbms
jass12345
 

Recently uploaded (20)

PDF
Electrical Engineer operation Supervisor
ssaruntatapower143
 
PDF
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
PDF
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
PDF
REINFORCEMENT LEARNING IN DECISION MAKING SEMINAR REPORT
anushaashraf20
 
PDF
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
PPTX
OCS353 DATA SCIENCE FUNDAMENTALS- Unit 1 Introduction to Data Science
A R SIVANESH M.E., (Ph.D)
 
PPTX
What is Shot Peening | Shot Peening is a Surface Treatment Process
Vibra Finish
 
PPTX
MODULE 03 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
PDF
SERVERLESS PERSONAL TO-DO LIST APPLICATION
anushaashraf20
 
PPTX
Distribution reservoir and service storage pptx
dhanashree78
 
PPTX
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
PPTX
Knowledge Representation : Semantic Networks
Amity University, Patna
 
PDF
Submit Your Papers-International Journal on Cybernetics & Informatics ( IJCI)
IJCI JOURNAL
 
PPTX
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
PDF
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
PDF
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
PDF
Halide Perovskites’ Multifunctional Properties: Coordination Engineering, Coo...
TaameBerhe2
 
PDF
mbse_An_Introduction_to_Arcadia_20150115.pdf
henriqueltorres1
 
PDF
AN EMPIRICAL STUDY ON THE USAGE OF SOCIAL MEDIA IN GERMAN B2C-ONLINE STORES
ijait
 
PDF
Data structures notes for unit 2 in computer science.pdf
sshubhamsingh265
 
Electrical Engineer operation Supervisor
ssaruntatapower143
 
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
REINFORCEMENT LEARNING IN DECISION MAKING SEMINAR REPORT
anushaashraf20
 
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
OCS353 DATA SCIENCE FUNDAMENTALS- Unit 1 Introduction to Data Science
A R SIVANESH M.E., (Ph.D)
 
What is Shot Peening | Shot Peening is a Surface Treatment Process
Vibra Finish
 
MODULE 03 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
SERVERLESS PERSONAL TO-DO LIST APPLICATION
anushaashraf20
 
Distribution reservoir and service storage pptx
dhanashree78
 
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
Knowledge Representation : Semantic Networks
Amity University, Patna
 
Submit Your Papers-International Journal on Cybernetics & Informatics ( IJCI)
IJCI JOURNAL
 
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
Halide Perovskites’ Multifunctional Properties: Coordination Engineering, Coo...
TaameBerhe2
 
mbse_An_Introduction_to_Arcadia_20150115.pdf
henriqueltorres1
 
AN EMPIRICAL STUDY ON THE USAGE OF SOCIAL MEDIA IN GERMAN B2C-ONLINE STORES
ijait
 
Data structures notes for unit 2 in computer science.pdf
sshubhamsingh265
 
Ad

Introduction to database and sql fir beginers

  • 2. index  What is SQL  What Can SQL do?  SQL Commands  SQL Aggregate Functions  SQL Joins
  • 3. What is SQL? • SQL stands for Structured Query Language • SQL lets you access and manipulate databases • SQL became a standard of the American National Standards Institute (ANSI) in 1986, and of the International Organization for Standardization (ISO) in 1987
  • 4. What Can SQL do? • SQL can execute queries against a database • SQL can retrieve data from a database • SQL can insert records in a database • SQL can update records in a database • SQL can delete records from a database • SQL can create new databases • SQL can create new tables in a database • SQL can create stored procedures in a database • SQL can create views in a database • SQL can set permissions on tables, procedures, and views
  • 5. SQL Commands • Types of SQL Commands: • DDL (Data Definition Language): • DML (Data Manipulation Language): • DCL (Data Control Language • TCL (Transaction Control Language)
  • 6. Data Definition Language (DDL) Commands Data Definition Language, is a subset of SQL (Structured Query Language) commands used to define and modify the database structure. These commands are used to create, alter, and delete database objects like tables, indexes, and schemas. 1. CREATE: Creates a new table or database. 2. ALTER: Modifies an existing database object. 3. DROP: Deletes an entire table, database, or other objects. 4. TRUNCATE: Removes all records from a table, deleting the space allocated for the records. DDL commands play a crucial role in defining the database schema.
  • 7. The primary DDL commands in SQL include: • CREATE: This command is used to create a new database object. For example, creating a new table, a view, or a database. Syntax for creating a table: CREATE TABLE table_name (column1 datatype, column2 datatype, ...); ALTER: This command is used to modify an existing database object, such as adding, deleting, or modifying columns in an existing table. Syntax for adding a column in a table: ALTER TABLE table_name ADD column_name datatype; Syntax for modifying a column in a table: ALTER TABLE table_name MODIFY COLUMN column_name datatype;
  • 8. • TRUNCATE: This command is used to delete all data from a table, but the structure of the table remains. It’s a fast way to clear large data from a table. Syntax: TRUNCATE TABLE table_name; • COMMENT: Used to add comments to the data dictionary. Syntax: COMMENT ON TABLE table_name IS 'This is a comment.’; • RENAME: Used to rename an existing database object.
  • 9. Data Manipulation Language (DML) Data Manipulation Language (DML) is a subset of SQL commands used for adding (inserting), deleting, and modifying (updating) data in a database. DML commands are crucial for managing the data within the tables of a database. 1. SELECT: Retrieves data from the database. 2. INSERT: Adds new data to a table. 3. UPDATE: Modifies existing data within a table. 4. DELETE: Removes data from a table.
  • 10. INSERT: This command is used to add new rows (records) to a table. Syntax: INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...); UPDATE: This command is used to modify the existing records in a table. Syntax: UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition; The WHERE clause specifies which records should be updated. Without it, all records in the table will be updated. DELETE: This command is used to remove one or more rows from a table. Syntax: DELETE FROM table_name WHERE condition; Like with UPDATE, the WHERE clause specifies which rows should be deleted. Omitting the WHERE clause will result in all rows being deleted
  • 11. SELECT: Although often categorized separately, the SELECT command is sometimes considered part of DML as it is used to retrieve data from the database. Syntax: SELECT column1, column2, ... FROM table_name WHERE condition; The SELECT statement is used to query and extract data from a table, which can then be used for various purposes.
  • 12. Data Control Language (DCL) Commands in SQL Data Control Language (DCL) is a subset of SQL commands used to control access to data in a database. DCL is crucial for ensuring security and proper data management, especially in multi-user database environments. • GRANT: This command is used to give users access privileges to the database. These privileges can include the ability to select, insert, update, delete, and so on, over database objects like tables and views. Syntax: GRANT privilege_name ON object_name TO user_name; For example, GRANT SELECT ON employees TO user123; gives user123 the permission to read data from the employees table.
  • 13. • REVOKE: This command is used to remove previously granted access privileges from a user. Syntax: REVOKE privilege_name ON object_name FROM user_name; For example, REVOKE SELECT ON employees FROM user123; would remove user123‘s permission to read data from the employees table.
  • 14. Transaction Control Language (TCL) Transaction Control Language, is a subset of SQL used to manage database transactions. TCL commands ensure data integrity by allowing you to control when changes to the database are saved permanently or rolled back. COMMIT:The COMMIT command is used to save changes made during a transaction to the database permanently: BEGIN; -- SQL statements COMMIT;
  • 15. ROLLBACK:The ROLLBACK command is used to undo changes made during a transaction: BEGIN; -- SQL statements ROLLBACK; This example begins a transaction, performs SQL statements, and then rolls back the changes, restoring the database to its previous state. SAVEPOINT:The SAVEPOINT command allows you to set a point within a transaction to which you can later roll back: BEGIN; -- SQL statements SAVEPOINT my_savepoint; -- More SQL statements ROLLBACK TO my_savepoint; This example creates a savepoint and later rolls back to that point,
  • 16. SQL Aggregate Functions • MIN() - returns the smallest value within the selected column Syntax: SELECT MIN(column_name) FROM table_name WHERE condition; • Example: SELECT MIN(Price)FROM Products; • MAX() - returns the largest value within the selected column Syntax: SELECT MAX(column_name) FROM table_name WHERE condition; • Example: SELECT MAX(Price)FROM Products;
  • 17. • COUNT() - returns the number of rows in a set Syntax SELECT COUNT(column_name) FROM table_name WHERE condition; • Example: SELECT COUNT(*) FROM Products; • SUM() - returns the total sum of a numerical column Syntax SELECT SUM(column_name) FROM table_name WHERE condition; • Example:SELECT SUM(Quantity) FROM OrderDetails; • AVG() - returns the average value of a numerical column • Syntax SELECT AVG(column_name) FROM table_name WHERE condition; Example:SELECT AVG(Price) FROM Products;
  • 18. SQL Joins A JOIN clause is used to combine rows from two or more tables, based on a related column between them. SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate FROM Orders INNER JOIN Customers ON Orders.CustomerID=Customers.CustomerID;
  • 19. Different Types of SQL JOINs • (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
  • 20. The SQL SELECT DISTINCT Statement The SELECT DISTINCT statement is used to return only distinct (different) values. Syntax SELECT DISTINCT column1, column2, ... FROM table_name; Example
  • 21. SQL WHERE Clause The WHERE clause is used to filter records. It is used to extract only those records that fulfill a specified condition. Example SQL ORDER BY Keyword The ORDER BY keyword is used to sort the result-set in ascending or descending order. Example