Chapter 4
Chapter 4
Chapter 4
BASIC SQL
SQL
The name SQL is presently expanded as Structured
Query Language. Originally, SQL was called
SEQUEL (Structured English QUEry Language) and
was designed and implemented at IBM Research as
the interface for an experimental relational database
system called SYSTEM R.
SQL is a comprehensive database language: It has
statements for data definitions, queries, and updates.
Hence, it is both a DDL and a DML.
In addition, it has facilities for defining views, for
specifying security and authorization for defining
integrity constraints.
Outline
SQL Data Definition and Data Types
Specify Constraints in SQL
Basic Retrieval in SQL
INSERT, DELETE and UPDATE
Statement
Data Definition, Constraints,
and Schema Changes
Used to CREATE, DROP, and ALTER the
descriptions of the tables (relations) of
a database
Slide 8-4
CREATE SCHEMA
Specifies a new database schema by
giving it a name
Slide 8-39
THE EXISTS FUNCTION (cont.)
Query 6: Retrieve the names of employees who have
no dependents.
Slide 8-40
EXPLICIT SETS
It is also possible to use an explicit (enumerated)
set of values in the WHERE-clause rather than a
nested query
Query 13: Retrieve the social security numbers of all
employees who work on project number 1, 2, or 3.
Slide 8-41
NULLS IN SQL QUERIES
SQL allows queries that check if a value is NULL
(missing or undefined or not applicable)
SQL uses IS or IS NOT to compare NULLs because
it considers each NULL value distinct from other
NULL values, so equality comparison is not
appropriate .
Query 14: Retrieve the names of all employees who
do not have supervisors.
Q14: SELECT FNAME, LNAME
FROMEMPLOYEE
WHERE SUPERSSN IS NULL
Note: If a join condition is specified, tuples withSlide 8-42
Outline
SQL Data Definition and Data Types
Specify Constraints in SQL
Basic Retrieval in SQL
INSERT, DELETE and UPDATE
Statement
Modification in Database
In SQL, three commands can be used
to modify the database: INSERT,
DELETE, and UPDATE.
Use of INSERT
Use of DELETE
Use of UPDATE