SlideShare a Scribd company logo
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

More Related Content

PPT
SQL Tutorial - Basic Commands
PPTX
Creating database using sql commands
PPTX
Lab2 ddl commands
PPTX
SQL Basics
PPT
Advanced Sql Training
PPT
Introduction to-sql
PPT
Sql – Structured Query Language
SQL Tutorial - Basic Commands
Creating database using sql commands
Lab2 ddl commands
SQL Basics
Advanced Sql Training
Introduction to-sql
Sql – Structured Query Language

What's hot (19)

PPT
SQL Tutorial - How To Create, Drop, and Truncate Table
PPT
Introduction to structured query language (sql)
PDF
Sql Basics | Edureka
PPTX
DDL,DML,SQL Functions and Joins
PPT
SQL DDL
DOC
A must Sql notes for beginners
PPTX
STRUCTURE OF SQL QUERIES
PDF
SQL Overview
PPT
SQL select statement and functions
PPTX
SQL Server Learning Drive
PPT
Sql select
PPTX
Oracle: Basic SQL
PPTX
SQL - Structured query language introduction
PPTX
SQL Commands
PPTX
Introduction to SQL
PPTX
SQL commands
PDF
Sql tutorial
PDF
Mysql cheatsheet
PPTX
DDL(Data defination Language ) Using Oracle
SQL Tutorial - How To Create, Drop, and Truncate Table
Introduction to structured query language (sql)
Sql Basics | Edureka
DDL,DML,SQL Functions and Joins
SQL DDL
A must Sql notes for beginners
STRUCTURE OF SQL QUERIES
SQL Overview
SQL select statement and functions
SQL Server Learning Drive
Sql select
Oracle: Basic SQL
SQL - Structured query language introduction
SQL Commands
Introduction to SQL
SQL commands
Sql tutorial
Mysql cheatsheet
DDL(Data defination Language ) Using Oracle
Ad

Viewers also liked (10)

PDF
Basic Sql Handouts
PDF
Sql basics joi ns and common commands (1)
PPTX
Sql Basic Selects
KEY
Lecture 07 - Basic SQL
PDF
Sql basics
PPTX
1. SQL Basics - Introduction
PPT
Writing Basic SQL SELECT Statements
PPT
Tables And SQL basics
PPT
4. SQL in DBMS
Basic Sql Handouts
Sql basics joi ns and common commands (1)
Sql Basic Selects
Lecture 07 - Basic SQL
Sql basics
1. SQL Basics - Introduction
Writing Basic SQL SELECT Statements
Tables And SQL basics
4. SQL in DBMS
Ad

Similar to Sql basics (20)

PPTX
SQl data base management and design
PDF
Chapter – 6 SQL Lab Tutorial.pdf
DOCX
PDF
SQL -Beginner To Intermediate Level.pdf
PPTX
PDF
Database Architecture and Basic Concepts
PPT
chapter 8 SQL.ppt
PPTX
HPD SQL Training - Beginner - 20220916.pptx
PDF
Structure query language, database course
PDF
Sq lite module6
PDF
Rdbms day3
PPTX
Advanced Database Systems - Presentation 2.pptx
PPTX
Database COMPLETE
DOC
Module 3
PPTX
SQL.pptx for the begineers and good know
PPTX
PPTX
SQL DATABASE MANAGAEMENT SYSTEM FOR CLASS 12 CBSE
PDF
PT- Oracle session01
PDF
BCS4L1-Database Management lab.pdf
PDF
database in my squel assignment for students.pdf
SQl data base management and design
Chapter – 6 SQL Lab Tutorial.pdf
SQL -Beginner To Intermediate Level.pdf
Database Architecture and Basic Concepts
chapter 8 SQL.ppt
HPD SQL Training - Beginner - 20220916.pptx
Structure query language, database course
Sq lite module6
Rdbms day3
Advanced Database Systems - Presentation 2.pptx
Database COMPLETE
Module 3
SQL.pptx for the begineers and good know
SQL DATABASE MANAGAEMENT SYSTEM FOR CLASS 12 CBSE
PT- Oracle session01
BCS4L1-Database Management lab.pdf
database in my squel assignment for students.pdf

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