Professional Documents
Culture Documents
Chap07 - Introduction To SQL
Chap07 - Introduction To SQL
Introduction to SQL
Modern Database
Management
8th Edition
Jeffrey A. Hoffer, Mary B. Prescott,
Fred R. McFadden
2007 by Prentice Hall
Objectives
Definition of terms
Interpret history and role of SQL
Define a database using SQL data
definition language
Write single table queries using SQL
Establish referential integrity using SQL
Discuss SQL:1999 and SQL:2003
standards
Chapter 7
SQL Overview
Chapter 7
History of SQL
Chapter 7
Chapter 7
Benefits of a Standardized
Relational Language
Chapter 7
Catalog
Schema
SQL Environment
Chapter 7
Figure 7-1
A simplified schematic of a typical SQL environment, as
described by the SQL-2003 standard
Chapter 7
Chapter 7
Figure 7-4
DDL, DML, DCL, and the database development process
Chapter 7
10
Chapter 7
11
Table Creation
Figure 7-5 General syntax for CREATE TABLE
Steps in table
creation:
1. Identify data types for
attributes
2. Identify columns that
can and cannot be
null
3. Identify columns that
must be unique
(candidate keys)
4. Identify primary key
foreign key mates
5. Determine default
values
Chapter 7
6. Identify constraints on
columns (domain
specifications) 12
2007 by Prentice Hall
Chapter 7
13
Figure 7-6 SQL database definition commands for Pine Valley Furniture
Overall table
definitions
Chapter 7
14
Chapter 7
15
Non-nullable specification
Primary keys
can never have
NULL values
16
Non-nullable specifications
Primary key
17
Domain constraint
Chapter 7
18
Primary key of
parent table
Foreign key of
dependent table
Chapter 7
19
Chapter 7
20
Relational
integrity is
enforced via
the primarykey to foreignkey match
Chapter 7
21
Chapter 7
22
Schema Definition
Choice of indexes
File organizations for base tables
File organizations for indexes
Data clustering
Statistics maintenance
Creating indexes
Chapter 7
23
Insert Statement
Chapter 7
24
Chapter 7
25
Delete Statement
Chapter 7
26
Update Statement
Chapter 7
27
Merge Statement
Chapter 7
28
SELECT Statement
SELECT
FROM
HAVING
Indicate the conditions under which a row will be included in the result
GROUP BY
WHERE
List the columns (and expressions) that should be returned from the query
ORDER BY
Chapter 7
29
Figure 7-10
SQL statement
processing
order (adapted
from van der
Lans, p.100)
Chapter 7
30
SELECT Example
31
32
SELECT Example
Using a Function
33
SELECT ExampleBoolean
Operators
Chapter 7
35
SELECT Example
36
SELECT Example
37
SELECT Example
Materialized View
Chapter 7
39
Chapter 7
40
Advantages of Views
Chapter 7
41
Disadvantages of Views
Chapter 7
42