SlideShare a Scribd company logo
SQL
Structured Query Language
PRIYABRAT KAR
• SQL is a standard language for accessing
databases.
• SELECT * FROM Customers;
 What is SQL?
• SQL stands for Structured Query Language.
• SQL lets you access and manipulate
databases
• SQL is an ANSI (American National
Standards Institute) standard
 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
 Semicolon after SQL Statements?
• Some database systems require a semicolon at the end
of each SQL statement.
• Semicolon is the standard way to separate each SQL
statement in database systems that allow more than one SQL
statement to be executed in the same call to the server.
• In this tutorial, we will use semicolon at the end of each
SQL statement.
 Some of The Most Important SQL Commands
• SELECT - extracts data from a database
• UPDATE - updates data in a database
• DELETE - deletes data from a database
• INSERT INTO - inserts new data into a
database
• CREATE DATABASE - creates a new
database
• ALTER DATABASE - modifies a database
• CREATE TABLE - creates a new table
• ALTER TABLE - modifies a table
• DROP TABLE - deletes a table
• CREATE INDEX - creates an index (search
key)
• DROP INDEX - deletes an index
 The SQL SELECT Statement
The SELECT statement is used to select data from a
database.
• The result is stored in a result table, called the result-
set.
• SQL SELECT Syntax
SELECT column_name,column_name
FROM table_name;
and
SELECT * FROM table_name;
 The SQL WHERE Clause
• The WHERE clause is used to extract only those records
that fulfill a specified criterion.
• SQL WHERE Syntax
SELECT column_name,column_name
FROM table_name
WHERE column_name operator value;
• The AND & OR operators are used to filter
records based on more than one condition.
 The SQL ORDER BY Keyword
• The ORDER BY keyword is used to sort the result-set by
one or more columns.
• The ORDER BY keyword sorts the records in ascending
order by default. To sort the records in a descending
order, you can use the DESC keyword.
• SQL ORDER BY Syntax
SELECT column_name, column_name
FROM table_name
ORDER BY column_name ASC|DESC, column_name
ASC|DESC;
 The SQL UPDATE Statement
• The UPDATE statement is used to update existing
records in a table.
• SQL UPDATE Syntax
UPDATE table_name
SET column1=value1,column2=value2,...
WHERE some_column=some_value;
 The SQL DELETE Statement
• The DELETE statement is used to delete rows in a
table.
• SQL DELETE Syntax
DELETE FROM table_name
WHERE some_column=some_value;
 The SQL LIKE Operator
• The LIKE operator is used to search for a specified
pattern in a column.
• SQL LIKE Syntax
SELECT column_name(s)
FROM table_name
WHERE column_name LIKE pattern;
 SQL Wildcard Characters
In SQL, wildcard characters are used with the SQL LIKE operator.
• SQL wildcards are used to search for data within a table.
With SQL, the wildcards are:
Wildcard Description
% A substitute for zero or more characters
_ A substitute for a single character
[charlist] Sets and ranges of characters to match
[!charlist] Matches only a character NOT specified within the
brackets
 SQL Joins
• SQL joins are used to combine rows from two or more
tables.
 Different SQL JOINs
• Before we continue with examples, we will list the types the
different SQL JOINs you can use:
• INNER JOIN: Returns all rows when there is at least one
match in BOTH tables
• LEFT JOIN: Return all rows from the left table, and the
matched rows from the right table
• RIGHT JOIN: Return all rows from the right table, and the
matched rows from the left table
• FULL JOIN: Return all rows when there is a match in ONE
of the tables
 SQL INNER JOIN Keyword
• The INNER JOIN keyword selects all rows from
both tables as long as there is a match between the
columns in both tables.
• SQL INNER JOIN Syntax
SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name=table2.column_name;
or:
• SELECT column_name(s)
FROM table1
JOIN table2
ON table1.column_name=table2.column_name;
PS! INNER JOIN is the same as JOIN.
Sql Tutorials
 SQL LEFT JOIN Keyword
• The LEFT JOIN keyword returns all rows from the left table
(table1), with the matching rows in the right table (table2).
The result is NULL in the right side when there is no match.
• SQL LEFT JOIN Syntax
SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name=table2.column_name;
or:
• SELECT column_name(s)
FROM table1
LEFT OUTER JOIN table2
ON table1.column_name=table2.column_name;
Sql Tutorials
 SQL RIGHT JOIN Keyword
• The RIGHT JOIN keyword returns all rows from the right
table (table2), with the matching rows in the left table
(table1). The result is NULL in the left side when there is
no match.
• SQL RIGHT JOIN Syntax
SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name=table2.column_name;
or:
• SELECT column_name(s)
FROM table1
RIGHT OUTER JOIN table2
ON table1.column_name=table2.column_name;
Sql Tutorials
 SQL FULL OUTER JOIN Keyword
• The FULL OUTER JOIN keyword returns all rows
from the left table (table1) and from the right table
(table2).
• The FULL OUTER JOIN keyword combines the
result of both LEFT and RIGHT joins.
• SQL FULL OUTER JOIN Syntax
SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2
ON table1.column_name=table2.column_name;
Sql Tutorials
 The SQL CREATE TABLE Statement
• The CREATE TABLE statement is used to create a
table in a database.
• Tables are organized into rows and columns; and each
table must have a name.
• SQL CREATE TABLE Syntax
CREATE TABLE table_name
(
column_name1 data_type(size),
column_name2 data_type(size),
column_name3 data_type(size),
....
);
 SQL Constraints
SQL constraints are used to specify rules for the data in a table.
• If there is any violation between the constraint and the data
action, the action is aborted by the constraint.
• Constraints can be specified when the table is created (inside the
CREATE TABLE statement) or after the table is created (inside
the ALTER TABLE statement).
• SQL CREATE TABLE + CONSTRAINT Syntax
CREATE TABLE table_name
(
column_name1 data_type(size) constraint_name,
column_name2 data_type(size) constraint_name,
column_name3 data_type(size) constraint_name,
....
);
 In SQL, we have the following constraints:
• NOT NULL - Indicates that a column cannot store NULL
value
• UNIQUE - Ensures that each row for a column must have
a unique value
• PRIMARY KEY - A combination of a NOT NULL and
UNIQUE. Ensures that a column (or combination of two
or more columns) have an unique identity which helps to
find a particular record in a table more easily and quickly
• FOREIGN KEY - Ensure the referential integrity of the
data in one table to match values in another table
• CHECK - Ensures that the value in a column meets a
specific condition
• DEFAULT - Specifies a default value when specified
none for this column
 SQL Aggregate Functions
• SQL aggregate functions return a single
value, calculated from values in a column.
• Useful aggregate functions:
AVG() - Returns the average value
COUNT() - Returns the number of rows
FIRST() - Returns the first value
LAST() - Returns the last value
MAX() - Returns the largest value
MIN() - Returns the smallest value
SUM() - Returns the sum
 SQL Scalar functions
• SQL scalar functions return a single value, based on
the input value.
• Useful scalar functions:
UCASE() - Converts a field to upper case
LCASE() - Converts a field to lower case
MID() - Extract characters from a text field
LEN() - Returns the length of a text field
ROUND() - Rounds a numeric field to the number of
decimals specified
NOW() - Returns the current system date and time
FORMAT() - Formats how a field is to be displayed
Thank You

More Related Content

PPTX
Introduction to SQL
PDF
Katalon Studio - A Codeless Automation Tool.pdf
PPTX
How to win friends & influence people review
PDF
JavaScript - Chapter 12 - Document Object Model
PPT
Basic DBMS ppt
PPTX
SASS - CSS with Superpower
PDF
IBM DB2 for z/OS Administration Basics
 
Introduction to SQL
Katalon Studio - A Codeless Automation Tool.pdf
How to win friends & influence people review
JavaScript - Chapter 12 - Document Object Model
Basic DBMS ppt
SASS - CSS with Superpower
IBM DB2 for z/OS Administration Basics
 

What's hot (20)

PPTX
DATABASE CONSTRAINTS
PPTX
Joins And Its Types
PPT
Introduction to sql
PDF
SQL Queries - DDL Commands
PPTX
introdution to SQL and SQL functions
PPTX
SQL - DML and DDL Commands
PPTX
Group By, Order By, and Aliases in SQL
PPTX
Sql commands
PPTX
Sql queries presentation
PPT
SQL select statement and functions
PDF
Sql tutorial
PDF
Chapter 4 Structured Query Language
PPTX
8. sql
PPTX
Structured query language(sql)ppt
PPT
1 - Introduction to PL/SQL
PDF
SQL Overview
PPTX
Structured Query Language (SQL)
PPT
Introduction to-sql
PPTX
basic structure of SQL FINAL.pptx
DATABASE CONSTRAINTS
Joins And Its Types
Introduction to sql
SQL Queries - DDL Commands
introdution to SQL and SQL functions
SQL - DML and DDL Commands
Group By, Order By, and Aliases in SQL
Sql commands
Sql queries presentation
SQL select statement and functions
Sql tutorial
Chapter 4 Structured Query Language
8. sql
Structured query language(sql)ppt
1 - Introduction to PL/SQL
SQL Overview
Structured Query Language (SQL)
Introduction to-sql
basic structure of SQL FINAL.pptx
Ad

Similar to Sql Tutorials (20)

PPTX
2..basic queries.pptx
PPTX
PPTX
askndmf,dskmlf,bvdmk,v nmdsvjkmc,dvjkcmsdcvjnkmd
PPTX
SQL Data types and Constarints.pptx
PPTX
Aggregate functions in SQL.pptx
PPTX
Aggregate functions in SQL.pptx
PPTX
SQL Fundamentals
PPTX
Java class 8
PPTX
shs tvl ict_Programming Introduction to SQl.pptx
PPTX
4 SQL DML.pptx ASHEN WANNIARACHCHI USESS
PPTX
DBMS and SQL(structured query language) .pptx
PPTX
Sql slid
PDF
Complete SQL Tutorial In Hindi By Rishabh Mishra (Basic to Advance).pdf
PPTX
PPTX
Lesson-02 (1).pptx
PPT
UNIT2.ppt
PPTX
PPTX
View od dffmfmfmm,dm,f,dm,dfm,dddfdfsd,sd,sddf,df,ldf
PDF
Structure query language, database course
PDF
Sql overview-1232931296681161-1
2..basic queries.pptx
askndmf,dskmlf,bvdmk,v nmdsvjkmc,dvjkcmsdcvjnkmd
SQL Data types and Constarints.pptx
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
SQL Fundamentals
Java class 8
shs tvl ict_Programming Introduction to SQl.pptx
4 SQL DML.pptx ASHEN WANNIARACHCHI USESS
DBMS and SQL(structured query language) .pptx
Sql slid
Complete SQL Tutorial In Hindi By Rishabh Mishra (Basic to Advance).pdf
Lesson-02 (1).pptx
UNIT2.ppt
View od dffmfmfmm,dm,f,dm,dfm,dddfdfsd,sd,sddf,df,ldf
Structure query language, database course
Sql overview-1232931296681161-1
Ad

Recently uploaded (20)

PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PDF
PPT on Performance Review to get promotions
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPT
Project quality management in manufacturing
PPTX
OOP with Java - Java Introduction (Basics)
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPT
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
PDF
composite construction of structures.pdf
PPTX
Geodesy 1.pptx...............................................
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
Safety Seminar civil to be ensured for safe working.
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
UNIT 4 Total Quality Management .pptx
Foundation to blockchain - A guide to Blockchain Tech
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
R24 SURVEYING LAB MANUAL for civil enggi
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPT on Performance Review to get promotions
bas. eng. economics group 4 presentation 1.pptx
Project quality management in manufacturing
OOP with Java - Java Introduction (Basics)
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
CYBER-CRIMES AND SECURITY A guide to understanding
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
composite construction of structures.pdf
Geodesy 1.pptx...............................................
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Safety Seminar civil to be ensured for safe working.

Sql Tutorials

  • 2. • SQL is a standard language for accessing databases. • SELECT * FROM Customers;
  • 3.  What is SQL? • SQL stands for Structured Query Language. • SQL lets you access and manipulate databases • SQL is an ANSI (American National Standards Institute) standard
  • 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.  Semicolon after SQL Statements? • Some database systems require a semicolon at the end of each SQL statement. • Semicolon is the standard way to separate each SQL statement in database systems that allow more than one SQL statement to be executed in the same call to the server. • In this tutorial, we will use semicolon at the end of each SQL statement.
  • 6.  Some of The Most Important SQL Commands • SELECT - extracts data from a database • UPDATE - updates data in a database • DELETE - deletes data from a database • INSERT INTO - inserts new data into a database • CREATE DATABASE - creates a new database • ALTER DATABASE - modifies a database • CREATE TABLE - creates a new table • ALTER TABLE - modifies a table • DROP TABLE - deletes a table • CREATE INDEX - creates an index (search key) • DROP INDEX - deletes an index
  • 7.  The SQL SELECT Statement The SELECT statement is used to select data from a database. • The result is stored in a result table, called the result- set. • SQL SELECT Syntax SELECT column_name,column_name FROM table_name; and SELECT * FROM table_name;
  • 8.  The SQL WHERE Clause • The WHERE clause is used to extract only those records that fulfill a specified criterion. • SQL WHERE Syntax SELECT column_name,column_name FROM table_name WHERE column_name operator value; • The AND & OR operators are used to filter records based on more than one condition.
  • 9.  The SQL ORDER BY Keyword • The ORDER BY keyword is used to sort the result-set by one or more columns. • The ORDER BY keyword sorts the records in ascending order by default. To sort the records in a descending order, you can use the DESC keyword. • SQL ORDER BY Syntax SELECT column_name, column_name FROM table_name ORDER BY column_name ASC|DESC, column_name ASC|DESC;
  • 10.  The SQL UPDATE Statement • The UPDATE statement is used to update existing records in a table. • SQL UPDATE Syntax UPDATE table_name SET column1=value1,column2=value2,... WHERE some_column=some_value;
  • 11.  The SQL DELETE Statement • The DELETE statement is used to delete rows in a table. • SQL DELETE Syntax DELETE FROM table_name WHERE some_column=some_value;
  • 12.  The SQL LIKE Operator • The LIKE operator is used to search for a specified pattern in a column. • SQL LIKE Syntax SELECT column_name(s) FROM table_name WHERE column_name LIKE pattern;
  • 13.  SQL Wildcard Characters In SQL, wildcard characters are used with the SQL LIKE operator. • SQL wildcards are used to search for data within a table. With SQL, the wildcards are: Wildcard Description % A substitute for zero or more characters _ A substitute for a single character [charlist] Sets and ranges of characters to match [!charlist] Matches only a character NOT specified within the brackets
  • 14.  SQL Joins • SQL joins are used to combine rows from two or more tables.
  • 15.  Different SQL JOINs • Before we continue with examples, we will list the types the different SQL JOINs you can use: • INNER JOIN: Returns all rows when there is at least one match in BOTH tables • LEFT JOIN: Return all rows from the left table, and the matched rows from the right table • RIGHT JOIN: Return all rows from the right table, and the matched rows from the left table • FULL JOIN: Return all rows when there is a match in ONE of the tables
  • 16.  SQL INNER JOIN Keyword • The INNER JOIN keyword selects all rows from both tables as long as there is a match between the columns in both tables. • SQL INNER JOIN Syntax SELECT column_name(s) FROM table1 INNER JOIN table2 ON table1.column_name=table2.column_name; or: • SELECT column_name(s) FROM table1 JOIN table2 ON table1.column_name=table2.column_name; PS! INNER JOIN is the same as JOIN.
  • 18.  SQL LEFT JOIN Keyword • The LEFT JOIN keyword returns all rows from the left table (table1), with the matching rows in the right table (table2). The result is NULL in the right side when there is no match. • SQL LEFT JOIN Syntax SELECT column_name(s) FROM table1 LEFT JOIN table2 ON table1.column_name=table2.column_name; or: • SELECT column_name(s) FROM table1 LEFT OUTER JOIN table2 ON table1.column_name=table2.column_name;
  • 20.  SQL RIGHT JOIN Keyword • The RIGHT JOIN keyword returns all rows from the right table (table2), with the matching rows in the left table (table1). The result is NULL in the left side when there is no match. • SQL RIGHT JOIN Syntax SELECT column_name(s) FROM table1 RIGHT JOIN table2 ON table1.column_name=table2.column_name; or: • SELECT column_name(s) FROM table1 RIGHT OUTER JOIN table2 ON table1.column_name=table2.column_name;
  • 22.  SQL FULL OUTER JOIN Keyword • The FULL OUTER JOIN keyword returns all rows from the left table (table1) and from the right table (table2). • The FULL OUTER JOIN keyword combines the result of both LEFT and RIGHT joins. • SQL FULL OUTER JOIN Syntax SELECT column_name(s) FROM table1 FULL OUTER JOIN table2 ON table1.column_name=table2.column_name;
  • 24.  The SQL CREATE TABLE Statement • The CREATE TABLE statement is used to create a table in a database. • Tables are organized into rows and columns; and each table must have a name. • SQL CREATE TABLE Syntax CREATE TABLE table_name ( column_name1 data_type(size), column_name2 data_type(size), column_name3 data_type(size), .... );
  • 25.  SQL Constraints SQL constraints are used to specify rules for the data in a table. • If there is any violation between the constraint and the data action, the action is aborted by the constraint. • Constraints can be specified when the table is created (inside the CREATE TABLE statement) or after the table is created (inside the ALTER TABLE statement). • SQL CREATE TABLE + CONSTRAINT Syntax CREATE TABLE table_name ( column_name1 data_type(size) constraint_name, column_name2 data_type(size) constraint_name, column_name3 data_type(size) constraint_name, .... );
  • 26.  In SQL, we have the following constraints: • NOT NULL - Indicates that a column cannot store NULL value • UNIQUE - Ensures that each row for a column must have a unique value • PRIMARY KEY - A combination of a NOT NULL and UNIQUE. Ensures that a column (or combination of two or more columns) have an unique identity which helps to find a particular record in a table more easily and quickly • FOREIGN KEY - Ensure the referential integrity of the data in one table to match values in another table • CHECK - Ensures that the value in a column meets a specific condition • DEFAULT - Specifies a default value when specified none for this column
  • 27.  SQL Aggregate Functions • SQL aggregate functions return a single value, calculated from values in a column. • Useful aggregate functions: AVG() - Returns the average value COUNT() - Returns the number of rows FIRST() - Returns the first value LAST() - Returns the last value MAX() - Returns the largest value MIN() - Returns the smallest value SUM() - Returns the sum
  • 28.  SQL Scalar functions • SQL scalar functions return a single value, based on the input value. • Useful scalar functions: UCASE() - Converts a field to upper case LCASE() - Converts a field to lower case MID() - Extract characters from a text field LEN() - Returns the length of a text field ROUND() - Rounds a numeric field to the number of decimals specified NOW() - Returns the current system date and time FORMAT() - Formats how a field is to be displayed