SlideShare a Scribd company logo
2
Most read
3
Most read
5
Most read
1
Structured Query Language (SQL)
What is SQL?
 Is a language of database, it includes database creation,
deletion, fetching rows and modifying rows etc.
 SQL is Structured Query Language, which is a computer
language for storing, manipulating and retrieving data stored in
relational database.
2
Why SQL?
• Allows users to access data in relational database management
systems.
• Allows users to describe the data.
• Allows users to define the data in database and manipulate that data.
• Allows users to create and drop databases and tables.
• Allows users to create view, stored procedure, functions in a database.
• Allows users to set permissions on tables, procedures and views
3
SQL Syntax
• SQL is followed by unique set of rules and guidelines called Syntax. This
tutorial gives you a quick start with SQL by listing all the basic SQL
Syntax:
• All the SQL statements start with any of the keywords like SELECT,
INSERT, UPDATE, DELETE, ALTER, DROP, CREATE, USE, SHOW and
all the statements end with a semicolon (;).
4
SQL Syntax
• Important point to be noted is that SQL is case insensitive, which
means SELECT and select have same meaning in SQL statements, but
MySQL makes difference in table names. So if you are working with
MySQL, then you need to give table names as they exist in the
database.
5
SQL Statements
Most of the actions you need to perform on a database are done with SQL
statements.
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.
6
SQL DML and DDL
SQL can be divided into two parts: The Data Manipulation
Language (DML) and the Data Definition Language (DDL).
7
DDL - Data Definition Language:
The DDL part of SQL permits database tables to be created or
deleted. It also defines indexes (keys), specifies links between
tables, and imposes constraints between tables. The most
important DDL statements in SQL are:
 CREATE DATABASE - creates a new database
 ALTER DATABASE - modifies a database
 CREATE TABLE - creates a new table
8
DDL - Data Definition Language:
 ALTER TABLE - modifies a table
 DROP TABLE - deletes a table
 CREATE INDEX - creates an index (search key)
 DROP INDEX - deletes an index
9
DML - Data Manipulation Language:
The query and update commands form the DML part of SQL:
 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
10
1. 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(s)
FROM table_name
And
SELECT * FROM table_name
Note: SQL is not case sensitive. SELECT is the same as select.
11
Example: SELECT
Table Name: Students
StudentsID LastName FirstName Address City
1 Cabuso Fernan San Pedro Puerto Princesa
2 Porras Ellen Grace Alfonso XIII Quezon
3 Dela Cruz Steven Tabon Quezon
Now we want to select the content of the columns named "LastName" and
"FirstName" from the table above.
We use the following SELECT statement:
SELECT LastName, FirstName
FROM Students
12
Example: SELECT
Table Name: Students
The result-set will look like this:
LastName FirstName
Cabuso Fernan
Porras Ellen Grace
Dela Cruz Steven
13
Example: SELECT
Table Name: Students
Now we want to select all the columns from the “Students"
table. We use the following SELECT statement:
SELECT *
FROM Students
Or
SELECT * FROM Students
Tip: The asterisk (*) is a quick way of selecting all columns!
14
Example: SELECT
Table Name: Students
The result-set will look like this:
StudentsID LastName FirstName Address City
1 Cabuso Fernan San Pedro Puerto Princesa
2 Porras Ellen Grace Alfonso XIII Quezon
3 Dela Cruz Steven Tabon Quezon
15
2. SQL SELECT DISTINCT Statement
In a table, some of the columns may contain duplicate values. This is
not a problem, however, sometimes you will want to list only the
different (distinct) values in a table.
The DISTINCT keyword can be used to return only distinct (different)
values.
SQL SELECT DISTINCT Syntax:
SELECT DISTINCT column_name(s)
FROM table_name
16
Example: SELECT DISTINCT
Table Name: Students
Now we want to select only the distinct values from the column
named "City" from the table above.
StudentsID LastName FirstName Address City
1 Cabuso Fernan San Pedro Puerto Princesa
2 Porras Ellen Grace Alfonso XIII Quezon
3 Dela Cruz Steven Tabon Quezon
17
Example: SELECT DISTINCT
Table Name: Students
We use the following SELECT statement:
SELECT DISTINCT City FROM Students
The result-set will look like this:
City
Puerto Princesa
Quezon
Thank you

More Related Content

PDF
chapter 2-DATABASE SYSTEM CONCEPTS AND architecture [Autosaved].pdf
PPTX
Medical Coding
PPTX
Exception Handling in object oriented programming using C++
PPTX
Introduction to SQL
PPT
SQL.ppt
PPTX
Minor disorders of pregnancy
PDF
1 introduction databases and database users
PPTX
Cloud computing
chapter 2-DATABASE SYSTEM CONCEPTS AND architecture [Autosaved].pdf
Medical Coding
Exception Handling in object oriented programming using C++
Introduction to SQL
SQL.ppt
Minor disorders of pregnancy
1 introduction databases and database users
Cloud computing

What's hot (20)

PPTX
The Relational Database Model
PPTX
DATABASE CONSTRAINTS
PPT
Constraints In Sql
PPTX
Relational model
PPSX
Functional dependency
PPTX
database language ppt.pptx
PPTX
Integrity Constraints
PPTX
Sql fundamentals
PPTX
Database and types of database
PPT
Aggregate functions
PPTX
CPU Scheduling in OS Presentation
PPTX
Concurrency control
PDF
Object oriented databases
PPTX
1.4 data independence
PPTX
Methods for handling deadlock
PPTX
File system vs DBMS
PPTX
Structured Query Language (SQL)
PPT
File access methods.54
PDF
Normalization in DBMS
The Relational Database Model
DATABASE CONSTRAINTS
Constraints In Sql
Relational model
Functional dependency
database language ppt.pptx
Integrity Constraints
Sql fundamentals
Database and types of database
Aggregate functions
CPU Scheduling in OS Presentation
Concurrency control
Object oriented databases
1.4 data independence
Methods for handling deadlock
File system vs DBMS
Structured Query Language (SQL)
File access methods.54
Normalization in DBMS
Ad

Similar to Structured Query Language (SQL).pptx (20)

PPTX
Advanced Database Systems - Presentation 2.pptx
PDF
Sql tutorial
PPTX
SQL OVERVIEW for a new introduced student.pptx
PPTX
Advanced Database Systems - Presentation 3.pptx
PPTX
lovely
PDF
CS3481_Database Management Laboratory .pdf
PDF
SQL Complete Tutorial. All Topics Covered
PDF
BCS4L1-Database Management lab.pdf
PPTX
Relational Database Language.pptx
PPTX
Sql basic things
PPTX
introduction to SQL query language beginner.ppt
PDF
SQL -Beginner To Intermediate Level.pdf
PPTX
Unit - II.pptx
PPTX
SQL commands in database managemant systems
PPTX
Introduction to SQl Commands.pptxhhjhvvb
PPTX
MS SQL - Database Programming Concepts by RSolutions
PDF
Lecture on DBMS & MySQL.pdf v. C. .
PPTX
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
PDF
Sql smart reference_by_prasad
PDF
Sql smart reference_by_prasad
Advanced Database Systems - Presentation 2.pptx
Sql tutorial
SQL OVERVIEW for a new introduced student.pptx
Advanced Database Systems - Presentation 3.pptx
lovely
CS3481_Database Management Laboratory .pdf
SQL Complete Tutorial. All Topics Covered
BCS4L1-Database Management lab.pdf
Relational Database Language.pptx
Sql basic things
introduction to SQL query language beginner.ppt
SQL -Beginner To Intermediate Level.pdf
Unit - II.pptx
SQL commands in database managemant systems
Introduction to SQl Commands.pptxhhjhvvb
MS SQL - Database Programming Concepts by RSolutions
Lecture on DBMS & MySQL.pdf v. C. .
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
Sql smart reference_by_prasad
Sql smart reference_by_prasad
Ad

More from EllenGracePorras (20)

PPTX
Lesson 6 Information Management for BSIT.pptx
PPTX
Information Management for BSIT Students.pptx
PPTX
.Net Technologies MessageBox using Visual basic.pptx
PPTX
5 Laboratory Basic Calculator using Visual basic.pptx
PPTX
.Net Technologies - Visual Basic . Net.pptx
PPTX
Geographic Information System Lesson 6 IT
PPTX
Lesson 6 Introduction to Human Computer Interaction.pptx
PPTX
Lesson 3 Introduction to Human Computer Interaction.pptx
PPTX
Lesson 5 Introduction to Human Computer Interaction
PPTX
Geographic Information Systems GIS for BSIT
PPTX
Lesson 3 Introduction to Human Computer Interaction.pptx
PPTX
Lesson 4 Introduction to Human Computer Interaction.pptx
PPTX
Geographic Information System(GIS).pptx
PPTX
Geographic Information Systems (GIS).pptx
PPTX
Advanced Database Systems.pptx
PPTX
Data Manipulation Language.pptx
PPTX
Advanced Database Systems - Presentation 4.pptx
PPTX
Advanced Database Systems - Presentation 1 with quiz.pptx
PPTX
Structured Query Language (SQL) Part 2.pptx
PPTX
SQL Where Clause.pptx
Lesson 6 Information Management for BSIT.pptx
Information Management for BSIT Students.pptx
.Net Technologies MessageBox using Visual basic.pptx
5 Laboratory Basic Calculator using Visual basic.pptx
.Net Technologies - Visual Basic . Net.pptx
Geographic Information System Lesson 6 IT
Lesson 6 Introduction to Human Computer Interaction.pptx
Lesson 3 Introduction to Human Computer Interaction.pptx
Lesson 5 Introduction to Human Computer Interaction
Geographic Information Systems GIS for BSIT
Lesson 3 Introduction to Human Computer Interaction.pptx
Lesson 4 Introduction to Human Computer Interaction.pptx
Geographic Information System(GIS).pptx
Geographic Information Systems (GIS).pptx
Advanced Database Systems.pptx
Data Manipulation Language.pptx
Advanced Database Systems - Presentation 4.pptx
Advanced Database Systems - Presentation 1 with quiz.pptx
Structured Query Language (SQL) Part 2.pptx
SQL Where Clause.pptx

Recently uploaded (20)

PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPT
Teaching material agriculture food technology
PDF
Approach and Philosophy of On baking technology
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Electronic commerce courselecture one. Pdf
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Encapsulation theory and applications.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Machine learning based COVID-19 study performance prediction
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Teaching material agriculture food technology
Approach and Philosophy of On baking technology
Building Integrated photovoltaic BIPV_UPV.pdf
Electronic commerce courselecture one. Pdf
sap open course for s4hana steps from ECC to s4
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Encapsulation theory and applications.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
Per capita expenditure prediction using model stacking based on satellite ima...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Programs and apps: productivity, graphics, security and other tools
Diabetes mellitus diagnosis method based random forest with bat algorithm
Machine learning based COVID-19 study performance prediction

Structured Query Language (SQL).pptx

  • 1. 1 Structured Query Language (SQL) What is SQL?  Is a language of database, it includes database creation, deletion, fetching rows and modifying rows etc.  SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving data stored in relational database.
  • 2. 2 Why SQL? • Allows users to access data in relational database management systems. • Allows users to describe the data. • Allows users to define the data in database and manipulate that data. • Allows users to create and drop databases and tables. • Allows users to create view, stored procedure, functions in a database. • Allows users to set permissions on tables, procedures and views
  • 3. 3 SQL Syntax • SQL is followed by unique set of rules and guidelines called Syntax. This tutorial gives you a quick start with SQL by listing all the basic SQL Syntax: • All the SQL statements start with any of the keywords like SELECT, INSERT, UPDATE, DELETE, ALTER, DROP, CREATE, USE, SHOW and all the statements end with a semicolon (;).
  • 4. 4 SQL Syntax • Important point to be noted is that SQL is case insensitive, which means SELECT and select have same meaning in SQL statements, but MySQL makes difference in table names. So if you are working with MySQL, then you need to give table names as they exist in the database.
  • 5. 5 SQL Statements Most of the actions you need to perform on a database are done with SQL statements. 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.
  • 6. 6 SQL DML and DDL SQL can be divided into two parts: The Data Manipulation Language (DML) and the Data Definition Language (DDL).
  • 7. 7 DDL - Data Definition Language: The DDL part of SQL permits database tables to be created or deleted. It also defines indexes (keys), specifies links between tables, and imposes constraints between tables. The most important DDL statements in SQL are:  CREATE DATABASE - creates a new database  ALTER DATABASE - modifies a database  CREATE TABLE - creates a new table
  • 8. 8 DDL - Data Definition Language:  ALTER TABLE - modifies a table  DROP TABLE - deletes a table  CREATE INDEX - creates an index (search key)  DROP INDEX - deletes an index
  • 9. 9 DML - Data Manipulation Language: The query and update commands form the DML part of SQL:  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
  • 10. 10 1. 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(s) FROM table_name And SELECT * FROM table_name Note: SQL is not case sensitive. SELECT is the same as select.
  • 11. 11 Example: SELECT Table Name: Students StudentsID LastName FirstName Address City 1 Cabuso Fernan San Pedro Puerto Princesa 2 Porras Ellen Grace Alfonso XIII Quezon 3 Dela Cruz Steven Tabon Quezon Now we want to select the content of the columns named "LastName" and "FirstName" from the table above. We use the following SELECT statement: SELECT LastName, FirstName FROM Students
  • 12. 12 Example: SELECT Table Name: Students The result-set will look like this: LastName FirstName Cabuso Fernan Porras Ellen Grace Dela Cruz Steven
  • 13. 13 Example: SELECT Table Name: Students Now we want to select all the columns from the “Students" table. We use the following SELECT statement: SELECT * FROM Students Or SELECT * FROM Students Tip: The asterisk (*) is a quick way of selecting all columns!
  • 14. 14 Example: SELECT Table Name: Students The result-set will look like this: StudentsID LastName FirstName Address City 1 Cabuso Fernan San Pedro Puerto Princesa 2 Porras Ellen Grace Alfonso XIII Quezon 3 Dela Cruz Steven Tabon Quezon
  • 15. 15 2. SQL SELECT DISTINCT Statement In a table, some of the columns may contain duplicate values. This is not a problem, however, sometimes you will want to list only the different (distinct) values in a table. The DISTINCT keyword can be used to return only distinct (different) values. SQL SELECT DISTINCT Syntax: SELECT DISTINCT column_name(s) FROM table_name
  • 16. 16 Example: SELECT DISTINCT Table Name: Students Now we want to select only the distinct values from the column named "City" from the table above. StudentsID LastName FirstName Address City 1 Cabuso Fernan San Pedro Puerto Princesa 2 Porras Ellen Grace Alfonso XIII Quezon 3 Dela Cruz Steven Tabon Quezon
  • 17. 17 Example: SELECT DISTINCT Table Name: Students We use the following SELECT statement: SELECT DISTINCT City FROM Students The result-set will look like this: City Puerto Princesa Quezon