SlideShare una empresa de Scribd logo
1 de 14
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

Más contenido relacionado

La actualidad más candente

Advanced php
Advanced phpAdvanced php
Advanced php
hamfu
 

La actualidad más candente (20)

Oracle Sql & PLSQL Complete guide
Oracle Sql & PLSQL Complete guideOracle Sql & PLSQL Complete guide
Oracle Sql & PLSQL Complete guide
 
Building a SQL Database that Works
Building a SQL Database that WorksBuilding a SQL Database that Works
Building a SQL Database that Works
 
Java for beginners
Java for beginnersJava for beginners
Java for beginners
 
Developing Applications with MySQL and Java for beginners
Developing Applications with MySQL and Java for beginnersDeveloping Applications with MySQL and Java for beginners
Developing Applications with MySQL and Java for beginners
 
14. Defining Classes
14. Defining Classes14. Defining Classes
14. Defining Classes
 
C# Advanced L03-XML+LINQ to XML
C# Advanced L03-XML+LINQ to XMLC# Advanced L03-XML+LINQ to XML
C# Advanced L03-XML+LINQ to XML
 
4 execution plans
4 execution plans4 execution plans
4 execution plans
 
MS SQL Database basic
MS SQL Database basicMS SQL Database basic
MS SQL Database basic
 
Scala Reflection & Runtime MetaProgramming
Scala Reflection & Runtime MetaProgrammingScala Reflection & Runtime MetaProgramming
Scala Reflection & Runtime MetaProgramming
 
The Ring programming language version 1.10 book - Part 47 of 212
The Ring programming language version 1.10 book - Part 47 of 212The Ring programming language version 1.10 book - Part 47 of 212
The Ring programming language version 1.10 book - Part 47 of 212
 
Solid and Sustainable Development in Scala
Solid and Sustainable Development in ScalaSolid and Sustainable Development in Scala
Solid and Sustainable Development in Scala
 
Scrap your query boilerplate with specql
Scrap your query boilerplate with specqlScrap your query boilerplate with specql
Scrap your query boilerplate with specql
 
The Ring programming language version 1.5.3 book - Part 37 of 184
The Ring programming language version 1.5.3 book - Part 37 of 184The Ring programming language version 1.5.3 book - Part 37 of 184
The Ring programming language version 1.5.3 book - Part 37 of 184
 
Week3
Week3Week3
Week3
 
Advanced php
Advanced phpAdvanced php
Advanced php
 
Slickdemo
SlickdemoSlickdemo
Slickdemo
 
Be Smart, Constrain Your Types to Free Your Brain!
Be Smart, Constrain Your Types to Free Your Brain!Be Smart, Constrain Your Types to Free Your Brain!
Be Smart, Constrain Your Types to Free Your Brain!
 
Sql
SqlSql
Sql
 
Sql functions
Sql functionsSql functions
Sql functions
 
ZIO Prelude - ZIO World 2021
ZIO Prelude - ZIO World 2021ZIO Prelude - ZIO World 2021
ZIO Prelude - ZIO World 2021
 

Destacado (11)

Lecture 4 software process model (2)
Lecture 4   software process model (2)Lecture 4   software process model (2)
Lecture 4 software process model (2)
 
Relational Data Model Introduction
Relational Data Model IntroductionRelational Data Model Introduction
Relational Data Model Introduction
 
Introduction: Databases and Database Users
Introduction: Databases and Database UsersIntroduction: Databases and Database Users
Introduction: Databases and Database Users
 
C++ OOPS Concept
C++ OOPS ConceptC++ OOPS Concept
C++ OOPS Concept
 
Rdbms
RdbmsRdbms
Rdbms
 
All data models in dbms
All data models in dbmsAll data models in dbms
All data models in dbms
 
Software Engg. process models
Software Engg. process modelsSoftware Engg. process models
Software Engg. process models
 
Sql ppt
Sql pptSql ppt
Sql ppt
 
Different data models
Different data modelsDifferent data models
Different data models
 
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
 
LinkedIn SlideShare: Knowledge, Well-Presented
LinkedIn SlideShare: Knowledge, Well-PresentedLinkedIn SlideShare: Knowledge, Well-Presented
LinkedIn SlideShare: Knowledge, Well-Presented
 

Similar a Sql

Complete SQL Tutorial In Hindi By Rishabh Mishra.pdf
Complete SQL Tutorial In Hindi By Rishabh Mishra.pdfComplete SQL Tutorial In Hindi By Rishabh Mishra.pdf
Complete SQL Tutorial In Hindi By Rishabh Mishra.pdf
ssuserb5bb0e
 
MySQL Database System Hiep Dinh
MySQL Database System Hiep DinhMySQL Database System Hiep Dinh
MySQL Database System Hiep Dinh
webhostingguy
 
No SQL, No problem - using MongoDB in Ruby
No SQL, No problem - using MongoDB in RubyNo SQL, No problem - using MongoDB in Ruby
No SQL, No problem - using MongoDB in Ruby
sbeam
 

Similar a Sql (20)

Complete SQL Tutorial In Hindi By Rishabh Mishra.pdf
Complete SQL Tutorial In Hindi By Rishabh Mishra.pdfComplete SQL Tutorial In Hindi By Rishabh Mishra.pdf
Complete SQL Tutorial In Hindi By Rishabh Mishra.pdf
 
Oracle Material.pdf
Oracle Material.pdfOracle Material.pdf
Oracle Material.pdf
 
Lesson-02 (1).pptx
Lesson-02 (1).pptxLesson-02 (1).pptx
Lesson-02 (1).pptx
 
Db1 lecture4
Db1 lecture4Db1 lecture4
Db1 lecture4
 
Sql
SqlSql
Sql
 
MySql slides (ppt)
MySql slides (ppt)MySql slides (ppt)
MySql slides (ppt)
 
Lab
LabLab
Lab
 
Harder Faster Stronger
Harder Faster StrongerHarder Faster Stronger
Harder Faster Stronger
 
MySQL Database System Hiep Dinh
MySQL Database System Hiep DinhMySQL Database System Hiep Dinh
MySQL Database System Hiep Dinh
 
mysqlHiep.ppt
mysqlHiep.pptmysqlHiep.ppt
mysqlHiep.ppt
 
New methods for exploiting ORM injections in Java applications
New methods for exploiting ORM injections in Java applicationsNew methods for exploiting ORM injections in Java applications
New methods for exploiting ORM injections in Java applications
 
No SQL, No problem - using MongoDB in Ruby
No SQL, No problem - using MongoDB in RubyNo SQL, No problem - using MongoDB in Ruby
No SQL, No problem - using MongoDB in Ruby
 
Dbms &amp; oracle
Dbms &amp; oracleDbms &amp; oracle
Dbms &amp; oracle
 
lab#1,2,3.pptx
lab#1,2,3.pptxlab#1,2,3.pptx
lab#1,2,3.pptx
 
dbs class 7.ppt
dbs class 7.pptdbs class 7.ppt
dbs class 7.ppt
 
Advanced SQL Webinar
Advanced SQL WebinarAdvanced SQL Webinar
Advanced SQL Webinar
 
Integrity constraints in dbms
Integrity constraints in dbmsIntegrity constraints in dbms
Integrity constraints in dbms
 
Relate
RelateRelate
Relate
 
Ms sql-server
Ms sql-serverMs sql-server
Ms sql-server
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 

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)");