Title: The Relational Model 2:
1Chapter 3
- The Relational Model 2
- SQL
Database Management
2Objectives
- Introduce the SQL language.
- Discuss the use of simple and compound conditions
in SQL. - Present the use of computed fields in SQL.
- Examine the use of SQL built-in functions.
3Objectives
- Discuss the use of nested SQL queries.
- Examine grouping in SQL.
- Examine the way tables can be joined in SQL.
- Discuss the union operator in SQL.
4Database Creation
- CREATE TABLE is used to describe the layout of a
table. - Typical restrictions are
- The table or column name can be no longer than 18
characters. - The name must start with a letter.
- The name can contain letters, numbers, and
underscores (_). - The name cannot contain spaces.
5Database Creation
- INTEGER
- Numbers with or without a decimal point.
- SMALLINT
- Uses less space than INTEGER.
- DECIMAL (p,q)
- P number of digits, q number of decimal places.
6Database Creation
- CHAR (n)
- Character string n places long.
- DATE
- Dates in DD-MON-YYYY or MM/DD/YYYY
7Figure 3.1Simple Retrieval
8Figure 3.2 SQL Query to List Part Table
9Figure 3.3 SQL Query with a WHERE Condition
10Table 3.1 Comparison Operators
11Figure 3.4 SQL Query to Find Customer 124s Name
12Figure 3.5 SQL Query to Find Customer Numbers
13Figure 3.6Compound Conditions
14Figure 3.7 SQL Query with a Negative Compound
Condition
15Figure 3.8Computed Fields
16Figure 3.9Sorting
17Figure 3.10Built-In Functions
18Figure 3.11 Built-In Functions
19Figure 3.12Nesting Queries
20Figure 3.13 Nesting Queries
21Figure 3.14 Using Subqueries
22Figure 3.15Grouping
23Figure 3.16 SQL Query Using HAVING Clause
to Impart Conditions on Groups
24Joining Tables
- In the SELECT clause, you indicate all the fields
you want to display. - In the FROM clause, you list all the tables
involved in the query. - In the WHERE clause, you give the condition that
restricts the data to be retrieved to only those
rows from the two tables that match.
25Figure 3.17 SQL Query to Join Data from Two
Different Tables
26Figure 3.18 Join Query with a Compound Condition
27Figure 3.19Union
28Figure 3.20Updating Tables
29Figure 3.21 and Figure 3.22 Adding and Deleting
Data