SlideShare a Scribd company logo
SQL – Structured Query
       Language




                 By Pratik Rathod
DATABASE
•   Organized collection of data
•   DBMS – Data Base Management System
•   Ex. Oracle, Microsoft SQL Server, IBM DB2
•   2 types of DBMS
    – Flat-file database
    – Relational database
SQL
• Structured Query Language -> RDBMS
• A little History
  – Developed by Donald D. Chamberlin & Raymond F.
    Boyce at IBM in 1970
  – Initially it was named as SEQUEL (Structured
    English Query Language)
• Queries – most commonly used operation & can be
  done by SELECT
• SQL is not case sensitive. 
SQL for…
•   Execute queries against database
•   Retrieve data from database
•   Insert, Update, Delete records in database
•   Create new tables in database
•   Set permissions on tables
•   “Persons” table in database

    ID         Firstname   Lastname   Address    City
              1Pratik      Rathod     memnagar   Ahmedabad
              2Pranav      Agarwal    Paldi      Ahmedabad
              3Karan       Koria      Girnar     Junagadh
SQL Statements
• Not case sensitive
• Semi columns
• SQL - DML – Data manipulation language           SQL

       - DDL - Data definition language
                                        DML                  DDL

                                                            CREATE
                                       SELECT              DATABASE
                                       UPDATE            ALTER DATABASE
                                       DELETE             CREATE TABLE
                                     INSERT INTO          ALTER TABLE
                                                          DROP TBALE
                                                          CREATE INDEX
                                                          DROP INDEX
SQL Syntax & Statements
• SELECT
Syntax : SELECT column_name(s) FROM table_name
Examples:
1) SELECT LastName,FirstName FROM Persons
2) SELECT * FROM Persons (* is a quick way to select all the columns)

Where our selected columns stored????...

           ID            Firstname      Lastname      Address       City
                        1Pratik         Rathod        memnagar      Ahmedabad
                        2Pranav         Agarwal       Paldi         Ahmedabad
                        3Karan          Koria         Girnar        Junagadh
SQL Syntax & Statements
• SELECT DISTINCT                        • Where (clause)
Syntax :                                 Syntax :
SELECT DISTINCT column_name(s)           SELECT column_name(s) FROM table_name
FROM table_name                             WHERE column_name operator value

Example:                                 Example:
SELECT DISTINCT City FROM Persons        SELECT * FROM Persons WHERE
                                            City=‘Ahmedabad‘
City

Ahmedabad
                         ID          Firstname Lastname   Address  City
Junagadh                            1Pratik    Rathod     memnagar Ahmedabad
                                    2Pranav    Agarwal    Paldi    Ahmedabad
SQL Syntax & Statements
• Operators in WHERE         • CREATE TABLE
  = Equals                   Syntax :
  <> or != Not equal         CREATE TABLE table_name
  > Greater than                 (
  < Less than                    column_name1 data_type,
                                 column_name2 data_type,
  >= Greater than or equal       column_name3 data_type,
  <= Less than or equal          ....
                                 )

                             Example:
                             CREATE TABLE Persons
                                (
                                Id int,
                                LastName varchar(255),
                                FirstName varchar(255),
                                Address varchar(255),
                                City varchar(255)
                                )
SQL Syntax & Statements
• AND (Operator)               • AND & OR together
Ex.                            Ex.
SELECT * FROM Persons          SELECT * FROM Persons WHERE
WHERE FirstName=‘Pranav‘ AND       LastName=‘Agarwal'
    LastName=‘Agarwal‘             AND (FirstName=‘Pranav' OR
                                   FirstName=‘Pratik')

• OR (Operator)
Ex.
SELECT * FROM Persons
WHERE FirstName=‘Pranav'
    OR FirstName=‘Pratik'
SQL Syntax & Statements
• ORDER BY (Clause)                    • INSERT INTO
Syntax : SELECT column_name(s)
    FROM table_name
                                           – To insert a new row
    ORDER BY column_name(s) ASC|DESC   Syntax : INSERT INTO table_name
                                          (column1, column2, column3,...)
Ex.                                       VALUES (value1, value2, value3,...)
1) SELECT * FROM Persons               Ex.
    ORDER BY LastName
                                       1) INSERT INTO Persons
2) SELECT * FROM Persons                   VALUES
    ORDER BY LastName DESC
                                           (4,‘Naman', ‘Shah', ‘gandhinagar', ‘g
                                           andhinagar')

                                       2) INSERT INTO Persons
                                           (P_Id, LastName, FirstName) VALUES
                                           (5, ‘Amin', ‘Jay')
SQL Syntax & Statements
• UPDATE                                    • DELETE
Syntax : UPDATE table_name                  Syntax : DELETE FROM table_name
    SET
    column1=value, column2=value2,...
    WHERE some_column=some_value            Example:
Ex.                                         1) DELETE * FROM Persons
                                            2) DELETE FROM Persons
UPDATE Persons                                 WHERE Lastname = ‘Rathod’
SET Address=‘Sector21',City=‘Gandhinagar'
   WHERE LastName=‘Shah' AND
   FirstName=‘Naman’                        CAUTION:
                                            DELETE cannot be undo.
SQL elements
Where to write this things??...
•   Install java platform with JDBC API
•   Install a driver
•   Install DBMS (if u don’t have any)
•   Set up Database
•   Load drivers (In java program)
•   Make connection (In java program)
•   Write SQL statements in your program.
    – E.g.
    Statement stmt = con.createStatement();
                       (
    stmt.executeUpdate "INSERT INTO COFFEES " +
                     "VALUES ('Colombian', 101, 7.99, 0, 0)");
Thank you

More Related Content

DOC
Sql plsql
prudhviraj_cse
 
PDF
1 data types
Ram Kedem
 
PDF
GQL CheatSheet 1.1
sones GmbH
 
PDF
GQL cheat sheet latest
sones GmbH
 
PDF
CREATE INDEX … USING VODKA. VODKA CONNECTING INDEXES, Олег Бартунов, Александ...
Ontico
 
DOCX
supporting t-sql scripts for Heap vs clustered table
Mahabubur Rahaman
 
KEY
Postgres rules
gisborne
 
PDF
Sql server difference faqs- 3
Umar Ali
 
Sql plsql
prudhviraj_cse
 
1 data types
Ram Kedem
 
GQL CheatSheet 1.1
sones GmbH
 
GQL cheat sheet latest
sones GmbH
 
CREATE INDEX … USING VODKA. VODKA CONNECTING INDEXES, Олег Бартунов, Александ...
Ontico
 
supporting t-sql scripts for Heap vs clustered table
Mahabubur Rahaman
 
Postgres rules
gisborne
 
Sql server difference faqs- 3
Umar Ali
 

What's hot (20)

PPT
Oracle Sql & PLSQL Complete guide
Raviteja Chowdary Adusumalli
 
PDF
Building a SQL Database that Works
PostgreSQL Experts, Inc.
 
PDF
Java for beginners
Saeid Zebardast
 
PDF
Developing Applications with MySQL and Java for beginners
Saeid Zebardast
 
PPT
14. Defining Classes
Intro C# Book
 
PDF
C# Advanced L03-XML+LINQ to XML
Mohammad Shaker
 
PDF
4 execution plans
Ram Kedem
 
PPTX
MS SQL Database basic
wali1195189
 
ODP
Scala Reflection & Runtime MetaProgramming
Meir Maor
 
PDF
The Ring programming language version 1.10 book - Part 47 of 212
Mahmoud Samir Fayed
 
PDF
Solid and Sustainable Development in Scala
scalaconfjp
 
PPTX
Scrap your query boilerplate with specql
Tatu Tarvainen
 
PDF
The Ring programming language version 1.5.3 book - Part 37 of 184
Mahmoud Samir Fayed
 
KEY
Week3
Will Gaybrick
 
PPT
Advanced php
hamfu
 
ODP
Slickdemo
Knoldus Inc.
 
PDF
Be Smart, Constrain Your Types to Free Your Brain!
Jorge Vásquez
 
PPTX
Sql
Rahul Singh
 
PDF
Sql functions
Ankit Dubey
 
PDF
ZIO Prelude - ZIO World 2021
Jorge Vásquez
 
Oracle Sql & PLSQL Complete guide
Raviteja Chowdary Adusumalli
 
Building a SQL Database that Works
PostgreSQL Experts, Inc.
 
Java for beginners
Saeid Zebardast
 
Developing Applications with MySQL and Java for beginners
Saeid Zebardast
 
14. Defining Classes
Intro C# Book
 
C# Advanced L03-XML+LINQ to XML
Mohammad Shaker
 
4 execution plans
Ram Kedem
 
MS SQL Database basic
wali1195189
 
Scala Reflection & Runtime MetaProgramming
Meir Maor
 
The Ring programming language version 1.10 book - Part 47 of 212
Mahmoud Samir Fayed
 
Solid and Sustainable Development in Scala
scalaconfjp
 
Scrap your query boilerplate with specql
Tatu Tarvainen
 
The Ring programming language version 1.5.3 book - Part 37 of 184
Mahmoud Samir Fayed
 
Advanced php
hamfu
 
Slickdemo
Knoldus Inc.
 
Be Smart, Constrain Your Types to Free Your Brain!
Jorge Vásquez
 
Sql functions
Ankit Dubey
 
ZIO Prelude - ZIO World 2021
Jorge Vásquez
 
Ad

Viewers also liked (11)

PPT
Lecture 4 software process model (2)
IIUI
 
PPTX
Relational Data Model Introduction
Nishant Munjal
 
PDF
Introduction: Databases and Database Users
sontumax
 
PDF
C++ OOPS Concept
Boopathi K
 
PPT
Rdbms
tech4us
 
PPTX
All data models in dbms
Naresh Kumar
 
PPTX
Software Engg. process models
Tauseef Ahmad
 
PPT
Sql ppt
Anuja Lad
 
PPT
Different data models
madhusha udayangani
 
PDF
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Beat Signer
 
PDF
LinkedIn SlideShare: Knowledge, Well-Presented
SlideShare
 
Lecture 4 software process model (2)
IIUI
 
Relational Data Model Introduction
Nishant Munjal
 
Introduction: Databases and Database Users
sontumax
 
C++ OOPS Concept
Boopathi K
 
Rdbms
tech4us
 
All data models in dbms
Naresh Kumar
 
Software Engg. process models
Tauseef Ahmad
 
Sql ppt
Anuja Lad
 
Different data models
madhusha udayangani
 
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Beat Signer
 
LinkedIn SlideShare: Knowledge, Well-Presented
SlideShare
 
Ad

Similar to Sql (20)

PPT
Sql – Structured Query Language
pandey3045_bit
 
PPTX
SQL Queries Information
Nishant Munjal
 
DOC
ORACLE PL/SQL TUTORIALS - OVERVIEW - SQL COMMANDS
Newyorksys.com
 
PPT
Db1 lecture4
Sherif Gad
 
PPT
MS SQL Server 1
Iblesoft
 
PPT
dbs class 7.ppt
MARasheed3
 
PDF
full detailled SQL notesquestion bank (1).pdf
yvpachorib23
 
PPTX
SQL Assessment Command Statements
Shaun Wilson
 
PPT
Sql
jyothislides
 
PPT
MY SQL
sundar
 
PPT
SQL. It education ppt for reference sql process coding
aditipandey498628
 
DOC
SQL
Shunya Ram
 
PPTX
rdbms parul university oracle dbms bca mca
VaibhavSrivastav52
 
PPTX
Sql basics
Genesis Omo
 
PDF
SQL-Notes.pdf mba students database note
MrSushilMaurya
 
PPTX
Avinash database
avibmas
 
DOCX
Sql
Archana Rout
 
PDF
SQL Notes
JitendraYadav351971
 
DOC
A must Sql notes for beginners
Ram Sagar Mourya
 
PPTX
Sql
Aman Lalpuria
 
Sql – Structured Query Language
pandey3045_bit
 
SQL Queries Information
Nishant Munjal
 
ORACLE PL/SQL TUTORIALS - OVERVIEW - SQL COMMANDS
Newyorksys.com
 
Db1 lecture4
Sherif Gad
 
MS SQL Server 1
Iblesoft
 
dbs class 7.ppt
MARasheed3
 
full detailled SQL notesquestion bank (1).pdf
yvpachorib23
 
SQL Assessment Command Statements
Shaun Wilson
 
MY SQL
sundar
 
SQL. It education ppt for reference sql process coding
aditipandey498628
 
rdbms parul university oracle dbms bca mca
VaibhavSrivastav52
 
Sql basics
Genesis Omo
 
SQL-Notes.pdf mba students database note
MrSushilMaurya
 
Avinash database
avibmas
 
A must Sql notes for beginners
Ram Sagar Mourya
 

Sql

  • 1. SQL – Structured Query Language By Pratik Rathod
  • 2. DATABASE • Organized collection of data • DBMS – Data Base Management System • Ex. Oracle, Microsoft SQL Server, IBM DB2 • 2 types of DBMS – Flat-file database – Relational database
  • 3. SQL • Structured Query Language -> RDBMS • A little History – Developed by Donald D. Chamberlin & Raymond F. Boyce at IBM in 1970 – Initially it was named as SEQUEL (Structured English Query Language) • Queries – most commonly used operation & can be done by SELECT • SQL is not case sensitive. 
  • 4. SQL for… • Execute queries against database • Retrieve data from database • Insert, Update, Delete records in database • Create new tables in database • Set permissions on tables • “Persons” table in database ID Firstname Lastname Address City 1Pratik Rathod memnagar Ahmedabad 2Pranav Agarwal Paldi Ahmedabad 3Karan Koria Girnar Junagadh
  • 5. SQL Statements • Not case sensitive • Semi columns • SQL - DML – Data manipulation language SQL - DDL - Data definition language DML DDL CREATE SELECT DATABASE UPDATE ALTER DATABASE DELETE CREATE TABLE INSERT INTO ALTER TABLE DROP TBALE CREATE INDEX DROP INDEX
  • 6. SQL Syntax & Statements • SELECT Syntax : SELECT column_name(s) FROM table_name Examples: 1) SELECT LastName,FirstName FROM Persons 2) SELECT * FROM Persons (* is a quick way to select all the columns) Where our selected columns stored????... ID Firstname Lastname Address City 1Pratik Rathod memnagar Ahmedabad 2Pranav Agarwal Paldi Ahmedabad 3Karan Koria Girnar Junagadh
  • 7. SQL Syntax & Statements • SELECT DISTINCT • Where (clause) Syntax : Syntax : SELECT DISTINCT column_name(s) SELECT column_name(s) FROM table_name FROM table_name WHERE column_name operator value Example: Example: SELECT DISTINCT City FROM Persons SELECT * FROM Persons WHERE City=‘Ahmedabad‘ City Ahmedabad ID Firstname Lastname Address City Junagadh 1Pratik Rathod memnagar Ahmedabad 2Pranav Agarwal Paldi Ahmedabad
  • 8. SQL Syntax & Statements • Operators in WHERE • CREATE TABLE = Equals Syntax : <> or != Not equal CREATE TABLE table_name > Greater than ( < Less than column_name1 data_type, column_name2 data_type, >= Greater than or equal column_name3 data_type, <= Less than or equal .... ) Example: CREATE TABLE Persons ( Id int, LastName varchar(255), FirstName varchar(255), Address varchar(255), City varchar(255) )
  • 9. SQL Syntax & Statements • AND (Operator) • AND & OR together Ex. Ex. SELECT * FROM Persons SELECT * FROM Persons WHERE WHERE FirstName=‘Pranav‘ AND LastName=‘Agarwal' LastName=‘Agarwal‘ AND (FirstName=‘Pranav' OR FirstName=‘Pratik') • OR (Operator) Ex. SELECT * FROM Persons WHERE FirstName=‘Pranav' OR FirstName=‘Pratik'
  • 10. SQL Syntax & Statements • ORDER BY (Clause) • INSERT INTO Syntax : SELECT column_name(s) FROM table_name – To insert a new row ORDER BY column_name(s) ASC|DESC Syntax : INSERT INTO table_name (column1, column2, column3,...) Ex. VALUES (value1, value2, value3,...) 1) SELECT * FROM Persons Ex. ORDER BY LastName 1) INSERT INTO Persons 2) SELECT * FROM Persons VALUES ORDER BY LastName DESC (4,‘Naman', ‘Shah', ‘gandhinagar', ‘g andhinagar') 2) INSERT INTO Persons (P_Id, LastName, FirstName) VALUES (5, ‘Amin', ‘Jay')
  • 11. SQL Syntax & Statements • UPDATE • DELETE Syntax : UPDATE table_name Syntax : DELETE FROM table_name SET column1=value, column2=value2,... WHERE some_column=some_value Example: Ex. 1) DELETE * FROM Persons 2) DELETE FROM Persons UPDATE Persons WHERE Lastname = ‘Rathod’ SET Address=‘Sector21',City=‘Gandhinagar' WHERE LastName=‘Shah' AND FirstName=‘Naman’ CAUTION: DELETE cannot be undo.
  • 13. Where to write this things??... • Install java platform with JDBC API • Install a driver • Install DBMS (if u don’t have any) • Set up Database • Load drivers (In java program) • Make connection (In java program) • Write SQL statements in your program. – E.g. Statement stmt = con.createStatement(); ( stmt.executeUpdate "INSERT INTO COFFEES " + "VALUES ('Colombian', 101, 7.99, 0, 0)");