SlideShare a Scribd company logo
2
Most read
4
Most read
6
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

PPT
Sql Commands_Dr.R.Shalini.ppt
PPTX
DBMS UNIT-2.pptx ggggggggggggggggggggggg
DOC
Oracle sql material
PDF
SQL-Notes.pdf mba students database note
PDF
PPTX
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
PPTX
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
PPTX
Unit - II.pptx
Sql Commands_Dr.R.Shalini.ppt
DBMS UNIT-2.pptx ggggggggggggggggggggggg
Oracle sql material
SQL-Notes.pdf mba students database note
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
Unit - II.pptx

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

PDF
SQL_NOTES.pdf
PPT
Mysql
PPTX
PPTX
Introduction to sql new
PDF
STRUCTURED QUERY LANGUAGE
PPTX
lovely
PPTX
introdution to SQL and SQL functions
PPT
Mysql Ppt
PPTX
SQL: Data Definition Language(DDL) command
PDF
Structures query language ___PPT (1).pdf
PPTX
Relational Database Language.pptx
PDF
Database management system unit 1 Bca 2-semester notes
PPTX
An intoduction to sql and its components
DOCX
ii bcom dbms SQL Commands.docx
PDF
sql notes Provideby AGN HUB Tech & It Solutions
PPTX
Using Basic Structured Query Language lo1.pptx
PPTX
SQL.pptx for the begineers and good know
PPTX
SQLBasic to advance for the beggineers.pptx
PPTX
SQL: Structured Query Language
SQL_NOTES.pdf
Mysql
Introduction to sql new
STRUCTURED QUERY LANGUAGE
lovely
introdution to SQL and SQL functions
Mysql Ppt
SQL: Data Definition Language(DDL) command
Structures query language ___PPT (1).pdf
Relational Database Language.pptx
Database management system unit 1 Bca 2-semester notes
An intoduction to sql and its components
ii bcom dbms SQL Commands.docx
sql notes Provideby AGN HUB Tech & It Solutions
Using Basic Structured Query Language lo1.pptx
SQL.pptx for the begineers and good know
SQLBasic to advance for the beggineers.pptx
SQL: Structured Query Language
Ad

Recently uploaded (20)

PPT
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
Construction Project Organization Group 2.pptx
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
additive manufacturing of ss316l using mig welding
PPT
Project quality management in manufacturing
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
Digital Logic Computer Design lecture notes
PPTX
Geodesy 1.pptx...............................................
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
DOCX
573137875-Attendance-Management-System-original
PPTX
OOP with Java - Java Introduction (Basics)
PDF
PPT on Performance Review to get promotions
PPTX
Sustainable Sites - Green Building Construction
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Construction Project Organization Group 2.pptx
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
additive manufacturing of ss316l using mig welding
Project quality management in manufacturing
CYBER-CRIMES AND SECURITY A guide to understanding
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Digital Logic Computer Design lecture notes
Geodesy 1.pptx...............................................
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
573137875-Attendance-Management-System-original
OOP with Java - Java Introduction (Basics)
PPT on Performance Review to get promotions
Sustainable Sites - Green Building Construction
Embodied AI: Ushering in the Next Era of Intelligent Systems
Automation-in-Manufacturing-Chapter-Introduction.pdf
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