SlideShare uma empresa Scribd logo
1 de 40
Genesis Omo
              1
 an acronym for Structured Query
  Language
 forms the backbone of most modern
  database systems
 the language of databases
 a standard programming language for
  querying and modifying data and
  managing databases.
 a standard computer language for
  accessing and manipulating databases.
                                          2
 SQL  allows you to access a database
 SQL is an ANSI standard computer
  language
 SQL can execute queries against a
  database
 SQL can retrieve data from a database
 SQL can insert new records in a database
 SQL can delete records from a database
 SQL can update records

                                             3
   The first version of SQL, initially called SEQUEL, was
    developed at IBM by Chamberlin and Boyce in the early
    1970s.
   later formally standardized by the American National
    Standards Institute (ANSI) in 1986.
   The first non-commercial non-SQL RDBMS, INGRES,
    was developed in 1974 at the U.C. Berkely. Ingres
    implemented a query language known as QUEL, which
    was later supplanted in the marketplace by SQL.
   In the late 1970s, Relational Software, Inc. (now Oracle
    Corp.) saw the potential of the concepts described by
    Codd, Chamberlin, and Boyce and developed their own
    SQL-based RDBMS.



                                                               4
   Statements which may have a persistent effect on
    schemas and data, or which may control transactions,
    program flow, connections, sessions, or diagnostics.
   Queries which retrieve data based on specific criteria.
   Expressions which can produce either scalar values or
    tables consisting of columns and rows of data.
   Predicates which specify conditions that can be
    evaluated to SQL three-valued logic (3VL).




                                                              5
   Clauses which are (in some cases optional) constituent
    components of statements and queries.
   Whitespace is generally ignored in SQL statements and
    queries, making it easier to format SQL code for
    readability.
   SQL statements also include the semicolon (";")
    statement terminator. Though not required on every
    platform, it is defined as a standard part of the SQL
    grammar.




                                                             6
• A database most often contains one or
  more tables.
• Each table is identified by a name (e.g.
  "Customers" or "Orders").

Tables contain records (rows) with data.




                                             7
8
   Table: Enrol
                          Class_Code
                          Stu_Num
 Table:
                          Enroll_Grade
 Student_Info
                        Table: Class
  •   Stu_Num               Class_Code
  •   Stu_LName             Crs_Cde
  •   Stu_Fname             Class_Section
                            Class_Room
  •   Stu_MName             Pro_Num
  •   Stu_Bdate
  •   Stu_Hrs           Table: Course
  •   Stu_Class           Crs_Code
                          Dept_Code
  •   Stu_GPA
                          Crs_Description
  •   Stu_Transfer        Crs_Credit
  •   Dept_Code
  •   Stu_Phone                              9
 With
     SQL, we can query a database and
 have a result set returned.

 SELECT   LastName FROM Persons




                                        10
 SQL  (Structured Query Language) is a
  syntax for executing queries.
 SQL language also includes a syntax to
  update, insert, and delete records.




                                           11
•   SELECT - extracts data from a database table
•   UPDATE - updates data in a database table
•   DELETE - deletes data from a database table
•   INSERT INTO - inserts new data into a
    database table




                                                   12
 Data  Definition Language (DDL) part of SQL
  permits database tables to be created or deleted.
 Define indexes (keys), specify links between
  tables, and impose constraints between
  database tables.




                                                      13
• CREATE TABLE - creates a new database table
• ALTER TABLE - alters (changes) a database table
• DROP TABLE - deletes a database table
• CREATE INDEX - creates an index (search key)
• DROP INDEX - deletes an index




                                                    14
 SELECT    statement is used to select data
  from a table.
 The tabular result is stored in a result table
  (called the resultset).

 Syntax
  SELECT column_name(s)
  FROM table_name


                                                   15
 Toselect the content of columns named
 "LastName" and "FirstName", from the
 database table called "Persons", use a

 SELECT   statement like this:

 SELECT   LastName,FirstName FROM
 Persons


                                          16
17
 Toselect all columns from the "Persons"
 table, use a * symbol instead of column
 names, like this:

 SELECT   * FROM Persons




                                            18
19
 The  DISTINCT keyword is used to return
  only distinct (different) values.
 The SELECT statement returns
  information from table columns. But what
  if we only want to select distinct
  elements?
 With SQL, all we need to do is to add a
  DISTINCT keyword to the SELECT
  statement:
Syntax :
SELECT DISTINCT column_name(s)
FROM table_name
                                             20
 Toselect ALL values from the column
 named "Company" we use a SELECT
 statement like this:

 SELECT   Company FROM Orders




                                        21
 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.




                                                22
 DISTINCT     keyword is used to return only
  distinct (different) values.
 SELECT statement returns information
  from table columns. But what if we only
  want to select distinct elements?

 Syntax
 SELECT DISTINCT column_name(s)
 FROM table_name
                                                23
 Toselect ALL values from the column
 named "Company" we use a SELECT
 statement like this:

 SELECT   Company FROM Orders




                                        24
25
 SELECT   DISTINCT Company FROM
 Orders




                                   26
 To
   conditionally select data from a table, a
 WHERE clause can be added to the
 SELECT statement.

 Syntax


 SELECT column FROM table
 WHERE column operator value


                                               27
28
 Toselect only the persons living in the city
 "Sandnes", we add a WHERE clause to
 the SELECT statement:




                                                 29
30
 Note that we have used single quotes
  around the conditional values in the
  examples.
 SQL uses single quotes around text values
  (most database systems will also accept
  double quotes). Numeric values
 should not be enclosed in quotes.




                                              31
 Thisis correct:
   SELECT * FROM Persons WHERE
FirstName='Tove'


 This   is wrong:

SELECT * FROM Persons WHERE
FirstName=Tove
                                 32
 This
     is correct:
  SELECT * FROM Persons WHERE
Year>1965


 Thisis wrong:
  SELECT * FROM Persons WHERE
Year>'1965'


                                33
 TheLIKE condition is used to specify a
 search for a pattern in a column.

 Syntax
  SELECT column FROM table
  WHERE column LIKE pattern

A "%" sign can be used to define wildcards
(missing letters in the pattern) both before
and after the pattern.
                                               34
 The    following SQL statement will return
    persons with first names that start with
    an 'O':
    SELECT * FROM Persons
    WHERE FirstName LIKE 'O%‘
 SELECT * FROM Persons
    WHERE FirstName LIKE '%a‘
 SELECT * FROM Persons
    WHERE FirstName LIKE '%la%'


                                               35
 INSERTINTO statement is used to insert
 new rows into a table.

 Syntax
 INSERT INTO table_name
 VALUES (value1, value2,....)

  INSERT INTO table_name (column1,
column2,...)
  VALUES (value1, value2,....)
                                           36
 This   "Persons" table:




                            37
INSERT INTO Persons VALUES ('Hetland', 'Camilla',
'Hagabakka 24', 'Sandnes')




                                                    38
Insert Data in Specified Columns
This "Persons" table:




                                   39
Tables:
 Customer
 Invoice
 Line
 Products
Identify the different fields per
table
 Inv_Number: inv,line                 Line_Price: line
 Cus_Code: cus,inv
                                       Inv_Date: inv
 Prod_Code: prod,line
 Cus_Lname: cus                       Prod_Descript: prod
 Cus_Fname: cus                       Prod_Price: prod
 Cus_Initial: cus
                                       Prod_On_Hand: prod
 Cus_Areacode: cus
 Cus_Phone: cus                       Vend_Code:prod
 Line_Units: line, prod



                                                              40

Mais conteúdo relacionado

Mais procurados

SQL Tutorial - How To Create, Drop, and Truncate Table
SQL Tutorial - How To Create, Drop, and Truncate TableSQL Tutorial - How To Create, Drop, and Truncate Table
SQL Tutorial - How To Create, Drop, and Truncate Table1keydata
 
Introduction to structured query language (sql)
Introduction to structured query language (sql)Introduction to structured query language (sql)
Introduction to structured query language (sql)Sabana Maharjan
 
Sql Basics | Edureka
Sql Basics | EdurekaSql Basics | Edureka
Sql Basics | EdurekaEdureka!
 
DDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and JoinsDDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and JoinsAshwin Dinoriya
 
A must Sql notes for beginners
A must Sql notes for beginnersA must Sql notes for beginners
A must Sql notes for beginnersRam Sagar Mourya
 
STRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESSTRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESVENNILAV6
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functionsVikas Gupta
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive TechandMate
 
SQL - Structured query language introduction
SQL - Structured query language introductionSQL - Structured query language introduction
SQL - Structured query language introductionSmriti Jain
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQLEhsan Hamzei
 
DDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using OracleDDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using OracleFarhan Aslam
 

Mais procurados (19)

SQL Tutorial - How To Create, Drop, and Truncate Table
SQL Tutorial - How To Create, Drop, and Truncate TableSQL Tutorial - How To Create, Drop, and Truncate Table
SQL Tutorial - How To Create, Drop, and Truncate Table
 
Introduction to structured query language (sql)
Introduction to structured query language (sql)Introduction to structured query language (sql)
Introduction to structured query language (sql)
 
Sql Basics | Edureka
Sql Basics | EdurekaSql Basics | Edureka
Sql Basics | Edureka
 
DDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and JoinsDDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and Joins
 
SQL DDL
SQL DDLSQL DDL
SQL DDL
 
A must Sql notes for beginners
A must Sql notes for beginnersA must Sql notes for beginners
A must Sql notes for beginners
 
STRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESSTRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIES
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functions
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive
 
Sql select
Sql select Sql select
Sql select
 
Oracle: Basic SQL
Oracle: Basic SQLOracle: Basic SQL
Oracle: Basic SQL
 
SQL - Structured query language introduction
SQL - Structured query language introductionSQL - Structured query language introduction
SQL - Structured query language introduction
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
 
SQL commands
SQL commandsSQL commands
SQL commands
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
Mysql cheatsheet
Mysql cheatsheetMysql cheatsheet
Mysql cheatsheet
 
DDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using OracleDDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using Oracle
 

Destaque (10)

Basic Sql Handouts
Basic Sql HandoutsBasic Sql Handouts
Basic Sql Handouts
 
Sql basics joi ns and common commands (1)
Sql basics  joi ns and common commands (1)Sql basics  joi ns and common commands (1)
Sql basics joi ns and common commands (1)
 
Sql Basic Selects
Sql Basic SelectsSql Basic Selects
Sql Basic Selects
 
Lecture 07 - Basic SQL
Lecture 07 - Basic SQLLecture 07 - Basic SQL
Lecture 07 - Basic SQL
 
Sql basics
Sql basicsSql basics
Sql basics
 
1. SQL Basics - Introduction
1. SQL Basics - Introduction1. SQL Basics - Introduction
1. SQL Basics - Introduction
 
Les01 Writing Basic Sql Statements
Les01 Writing Basic Sql StatementsLes01 Writing Basic Sql Statements
Les01 Writing Basic Sql Statements
 
Writing Basic SQL SELECT Statements
Writing Basic SQL SELECT StatementsWriting Basic SQL SELECT Statements
Writing Basic SQL SELECT Statements
 
Tables And SQL basics
Tables And SQL basicsTables And SQL basics
Tables And SQL basics
 
4. SQL in DBMS
4. SQL in DBMS4. SQL in DBMS
4. SQL in DBMS
 

Semelhante a Sql basics

Chapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdfChapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdfTamiratDejene1
 
SQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdfSQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdfDraguClaudiu
 
Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic ConceptsTony Wong
 
Advanced Database Systems - Presentation 2.pptx
Advanced Database Systems - Presentation 2.pptxAdvanced Database Systems - Presentation 2.pptx
Advanced Database Systems - Presentation 2.pptxEllenGracePorras
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETEAbrar ali
 
SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowPavithSingh
 
BCS4L1-Database Management lab.pdf
BCS4L1-Database Management lab.pdfBCS4L1-Database Management lab.pdf
BCS4L1-Database Management lab.pdfKeerthanaP37
 
Getting Started with MySQL I
Getting Started with MySQL IGetting Started with MySQL I
Getting Started with MySQL ISankhya_Analytics
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasadpaddu123
 

Semelhante a Sql basics (20)

Chapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdfChapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdf
 
Sql
SqlSql
Sql
 
SQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdfSQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdf
 
Lab
LabLab
Lab
 
Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic Concepts
 
chapter 8 SQL.ppt
chapter 8 SQL.pptchapter 8 SQL.ppt
chapter 8 SQL.ppt
 
Sq lite module6
Sq lite module6Sq lite module6
Sq lite module6
 
Rdbms day3
Rdbms day3Rdbms day3
Rdbms day3
 
Advanced Database Systems - Presentation 2.pptx
Advanced Database Systems - Presentation 2.pptxAdvanced Database Systems - Presentation 2.pptx
Advanced Database Systems - Presentation 2.pptx
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETE
 
Module 3
Module 3Module 3
Module 3
 
SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good know
 
Hira
HiraHira
Hira
 
PT- Oracle session01
PT- Oracle session01 PT- Oracle session01
PT- Oracle session01
 
BCS4L1-Database Management lab.pdf
BCS4L1-Database Management lab.pdfBCS4L1-Database Management lab.pdf
BCS4L1-Database Management lab.pdf
 
DBMS LAB M.docx
DBMS LAB M.docxDBMS LAB M.docx
DBMS LAB M.docx
 
Getting Started with MySQL I
Getting Started with MySQL IGetting Started with MySQL I
Getting Started with MySQL I
 
Database Overview
Database OverviewDatabase Overview
Database Overview
 
MYSQL.ppt
MYSQL.pptMYSQL.ppt
MYSQL.ppt
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasad
 

Sql basics

  • 2.  an acronym for Structured Query Language  forms the backbone of most modern database systems  the language of databases  a standard programming language for querying and modifying data and managing databases.  a standard computer language for accessing and manipulating databases. 2
  • 3.  SQL allows you to access a database  SQL is an ANSI standard computer language  SQL can execute queries against a database  SQL can retrieve data from a database  SQL can insert new records in a database  SQL can delete records from a database  SQL can update records 3
  • 4. The first version of SQL, initially called SEQUEL, was developed at IBM by Chamberlin and Boyce in the early 1970s.  later formally standardized by the American National Standards Institute (ANSI) in 1986.  The first non-commercial non-SQL RDBMS, INGRES, was developed in 1974 at the U.C. Berkely. Ingres implemented a query language known as QUEL, which was later supplanted in the marketplace by SQL.  In the late 1970s, Relational Software, Inc. (now Oracle Corp.) saw the potential of the concepts described by Codd, Chamberlin, and Boyce and developed their own SQL-based RDBMS. 4
  • 5. Statements which may have a persistent effect on schemas and data, or which may control transactions, program flow, connections, sessions, or diagnostics.  Queries which retrieve data based on specific criteria.  Expressions which can produce either scalar values or tables consisting of columns and rows of data.  Predicates which specify conditions that can be evaluated to SQL three-valued logic (3VL). 5
  • 6. Clauses which are (in some cases optional) constituent components of statements and queries.  Whitespace is generally ignored in SQL statements and queries, making it easier to format SQL code for readability.  SQL statements also include the semicolon (";") statement terminator. Though not required on every platform, it is defined as a standard part of the SQL grammar. 6
  • 7. • A database most often contains one or more tables. • Each table is identified by a name (e.g. "Customers" or "Orders"). Tables contain records (rows) with data. 7
  • 8. 8
  • 9. Table: Enrol  Class_Code  Stu_Num  Table:  Enroll_Grade Student_Info  Table: Class • Stu_Num  Class_Code • Stu_LName  Crs_Cde • Stu_Fname  Class_Section  Class_Room • Stu_MName  Pro_Num • Stu_Bdate • Stu_Hrs  Table: Course • Stu_Class  Crs_Code  Dept_Code • Stu_GPA  Crs_Description • Stu_Transfer  Crs_Credit • Dept_Code • Stu_Phone 9
  • 10.  With SQL, we can query a database and have a result set returned.  SELECT LastName FROM Persons 10
  • 11.  SQL (Structured Query Language) is a syntax for executing queries.  SQL language also includes a syntax to update, insert, and delete records. 11
  • 12. SELECT - extracts data from a database table • UPDATE - updates data in a database table • DELETE - deletes data from a database table • INSERT INTO - inserts new data into a database table 12
  • 13.  Data Definition Language (DDL) part of SQL permits database tables to be created or deleted.  Define indexes (keys), specify links between tables, and impose constraints between database tables. 13
  • 14. • CREATE TABLE - creates a new database table • ALTER TABLE - alters (changes) a database table • DROP TABLE - deletes a database table • CREATE INDEX - creates an index (search key) • DROP INDEX - deletes an index 14
  • 15.  SELECT statement is used to select data from a table.  The tabular result is stored in a result table (called the resultset).  Syntax SELECT column_name(s) FROM table_name 15
  • 16.  Toselect the content of columns named "LastName" and "FirstName", from the database table called "Persons", use a  SELECT statement like this:  SELECT LastName,FirstName FROM Persons 16
  • 17. 17
  • 18.  Toselect all columns from the "Persons" table, use a * symbol instead of column names, like this:  SELECT * FROM Persons 18
  • 19. 19
  • 20.  The DISTINCT keyword is used to return only distinct (different) values.  The SELECT statement returns information from table columns. But what if we only want to select distinct elements?  With SQL, all we need to do is to add a DISTINCT keyword to the SELECT statement: Syntax : SELECT DISTINCT column_name(s) FROM table_name 20
  • 21.  Toselect ALL values from the column named "Company" we use a SELECT statement like this:  SELECT Company FROM Orders 21
  • 22.  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. 22
  • 23.  DISTINCT keyword is used to return only distinct (different) values.  SELECT statement returns information from table columns. But what if we only want to select distinct elements?  Syntax SELECT DISTINCT column_name(s) FROM table_name 23
  • 24.  Toselect ALL values from the column named "Company" we use a SELECT statement like this:  SELECT Company FROM Orders 24
  • 25. 25
  • 26.  SELECT DISTINCT Company FROM Orders 26
  • 27.  To conditionally select data from a table, a WHERE clause can be added to the SELECT statement.  Syntax SELECT column FROM table WHERE column operator value 27
  • 28. 28
  • 29.  Toselect only the persons living in the city "Sandnes", we add a WHERE clause to the SELECT statement: 29
  • 30. 30
  • 31.  Note that we have used single quotes around the conditional values in the examples.  SQL uses single quotes around text values (most database systems will also accept double quotes). Numeric values  should not be enclosed in quotes. 31
  • 32.  Thisis correct: SELECT * FROM Persons WHERE FirstName='Tove'  This is wrong: SELECT * FROM Persons WHERE FirstName=Tove 32
  • 33.  This is correct: SELECT * FROM Persons WHERE Year>1965  Thisis wrong: SELECT * FROM Persons WHERE Year>'1965' 33
  • 34.  TheLIKE condition is used to specify a search for a pattern in a column.  Syntax SELECT column FROM table WHERE column LIKE pattern A "%" sign can be used to define wildcards (missing letters in the pattern) both before and after the pattern. 34
  • 35.  The following SQL statement will return persons with first names that start with an 'O':  SELECT * FROM Persons WHERE FirstName LIKE 'O%‘  SELECT * FROM Persons WHERE FirstName LIKE '%a‘  SELECT * FROM Persons WHERE FirstName LIKE '%la%' 35
  • 36.  INSERTINTO statement is used to insert new rows into a table.  Syntax INSERT INTO table_name VALUES (value1, value2,....) INSERT INTO table_name (column1, column2,...) VALUES (value1, value2,....) 36
  • 37.  This "Persons" table: 37
  • 38. INSERT INTO Persons VALUES ('Hetland', 'Camilla', 'Hagabakka 24', 'Sandnes') 38
  • 39. Insert Data in Specified Columns This "Persons" table: 39
  • 40. Tables:  Customer  Invoice  Line  Products Identify the different fields per table  Inv_Number: inv,line  Line_Price: line  Cus_Code: cus,inv  Inv_Date: inv  Prod_Code: prod,line  Cus_Lname: cus  Prod_Descript: prod  Cus_Fname: cus  Prod_Price: prod  Cus_Initial: cus  Prod_On_Hand: prod  Cus_Areacode: cus  Cus_Phone: cus  Vend_Code:prod  Line_Units: line, prod 40