Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Introduction to SQL
Modern Database
Management
10th Edition
Jeffrey A. Hoffer, V. Ramesh,
Heikki Topi
2011 Pearson Education, Inc. Publishing as
Prentice Hall
Objectives
Define 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:200n
standards
Chapter 6
SQL Overview
Chapter 6
History of SQL
Chapter 6
Chapter 6
Benefits of a Standardized
Relational Language
Chapter 6
Catalog
Schema
SQL Environment
Chapter 6
Figure 6-1
A simplified schematic of a typical SQL environment, as
described by the SQL: 200n standard
Chapter 6
Chapter 6
Figure 6-4
DDL, DML, DCL, and the database development process
Chapter 6
10
Chapter 6
11
Table Creation
Figure 6-5 General syntax for CREATE
TABLE statement used in data
definition language
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 6
6. Identify constraints on
columns (domain
specifications)
12
Chapter 6
13
Figure 6-6 SQL database definition commands for Pine Valley Furniture
Company (Oracle 11g)
Overall table
definitions
Chapter 6
14
Chapter 6
15
Non-nullable specification
Primary keys
can never have
NULL values
16
Non-nullable specifications
Primary key
17
Default value
Domain constraint
Chapter 6
18
Primary key of
parent table
19
Chapter 6
20
Relational
integrity is
enforced via
the primarykey to foreignkey match
Chapter 6
21
Changing Tables
Table Actions:
Chapter 6
22
Removing Tables
Chapter 6
23
Insert Statement
24
Chapter 6
25
Delete Statement
Chapter 6
26
Update Statement
Chapter 6
27
Merge Statement
Chapter 6
28
Schema Definition
Choice of indexes
File organizations for base tables
File organizations for indexes
Data clustering
Statistics maintenance
Creating indexes
Chapter 6
29
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 6
30
Figure 6-10
SQL statement
processing
order (adapted
from van der
Lans, 2006
p.100)
Chapter 6
31
SELECT Example
32
33
SELECT Example
Using a Function
34
SELECT ExampleBoolean
Operators
Chapter 6
36
SELECT ExampleBoolean
Operators
37
Chapter 6
38
SELECT Example
Note: the IN operator in this example allows you to include rows whose
CustomerState value is either FL, TX, CA, or HI. It is more efficient than
separate OR conditions.
Chapter 6
39
SELECT Example
40
SELECT Example
Materialized View
Chapter 6
42
43
Advantages of Views
Chapter 6
44
Disadvantages of Views
Chapter 6
45
Chapter 6
46