Professional Documents
Culture Documents
SYSTEMS
1.1
Database Management System (DBMS)
Collection of interrelated data
Set of programs to access the data
DBMS contains information about a particular enterprise
DBMS provides an environment that is both convenient and
efficient to use.
Database Applications:
Banking: all transactions
Airlines: reservations, schedules
Universities: registration, grades
Sales: customers, products, purchases
Manufacturing: production, inventory, orders, supply chain
Human resources: employee records, salaries, tax deductions
Databases touch all aspects of our lives
1.2
Purpose of Database System
1.3
Purpose of Database Systems (Cont.)
1.4
View of Data
An architecture for a database system
1.5
Instances and Schemas
Similar to types and variables in programming languages
Schema – the logical structure of the database
e.g., the database consists of information about a set of customers and
accounts and the relationship between them)
Analogous to type information of a variable in a program
Physical schema: database design at the physical level
Logical schema: database design at the logical level
Instance – the actual content of the database at a particular point in time
Analogous to the value of a variable
Physical Data Independence – the ability to modify the physical schema
without changing the logical schema
Applications depend on the logical schema
In general, the interfaces between the various levels and components should be
well defined so that changes in some parts do not seriously influence others.
1.6
Data Models
1.7
Entity-Relationship Model
1.8
Data Definition Language (DDL)
1.9
Data Manipulation Language (DML)
1.10
SQL
1.11
Database Users
1.12
Database Administrator
1.13
Entity Sets
1.14
Attributes
An entity is represented by a set of attributes, that is descriptive
properties possessed by all members of an entity set.
Example:
customer = (customer-id, customer-name,
customer-street, customer-city)
loan = (loan-number, amount)
Domain – the set of permitted values for each attribute
Attribute types:
Simple and composite attributes.
Single-valued and multi-valued attributes
E.g. multivalued attribute: phone-numbers
Derived attributes
Can be computed from other attributes
E.g. age, given date of birth
1.15
Composite Attributes
1.16
E-R Diagrams
1.18
Weak Entity Sets (Cont.)
We depict a weak entity set by double rectangles.
We underline the discriminator of a weak entity set with a
dashed line.
payment-number – discriminator of the payment entity set
Primary key for payment – (loan-number, payment-number)
1.19
Specialization
1.20
Specialization Example
1.21
SQL
1.22
Objectives
23
1.23
Introduction to SQL
24
1.24
Introduction to SQL (continued)
25
1.25
Introduction to SQL (continued)
26
1.26
Introduction to SQL (continued)
27
1.27
Introduction to SQL (continued)
28
1.28
Data Definition Commands
Examine simple database model and database tables that will form
basis for many SQL examples
Understand data environment
29
1.29
The Database Model
30
1.30
Creating the Database
31
1.31
The Database Schema
Authentication
33
1.33
Data Types (continued)
34
1.34
Creating Table Structures
35
1.35
Creating Table Structures (continued)
36
1.36
SQL Constraints
38
1.38
Data Manipulation Commands
39
1.39
Adding Table Rows
INSERT
40
1.40
Adding Table Rows (continued)
41
1.41
Saving Table Changes
42
1.42
Listing Table Rows
SELECT
43
1.43
Updating Table Rows
UPDATE
44
1.44
Restoring Table Contents
ROLLBACK
Used to restore database to its previous condition
Only applicable if COMMIT command has not
been used to permanently store changes in
database
Syntax:
ROLLBACK;
COMMIT and ROLLBACK only work with
data manipulation commands that are used
to add, modify, or delete table rows
45
1.45
Deleting Table Rows
DELETE
46
1.46
Inserting Table Rows with a
Select Subquery
INSERT
Syntax:
INSERT INTO tablename SELECT columnlist FROM
tablename;
47
1.47
Selecting Rows with
Conditional Restrictions
SELECT columnlist
FROM tablelist
[ WHERE conditionlist ] ;
48
1.48
Conditional Restrictions
(continued)
49
1.49
Selecting Rows with
Conditional Restrictions (continued)
50
1.50
Arithmetic Operators:
The Rule of Precedence
51
1.51
Arithmetic Operators:
The Rule of Precedence (continued)
52
1.52
Special Operators
BETWEEN
53
1.53
Special Operators (continued)
IN
54
1.54
Advanced Data Definition Commands
55
1.55
Changing a Column’s Data Type
56
1.56
Changing a Column’s Data
Characteristics
57
1.57
Adding a Column
58
1.58
Dropping a Column
59
1.59
Advanced Data Updates
60
1.60
Copying Parts of Tables
61
1.61
Adding Primary and Foreign Key
Designations
Syntax:
ALTER TABLE tablename ADD
PRIMARY KEY(fieldname);
For foreign key, use FOREIGN KEY in place of
PRIMARY KEY
62
1.62
Deleting a Table from the Database
DROP
63
1.63
Advanced Select Queries
Count
Find minimum and maximum values
Calculate averages
SQL allows user to limit queries to only those entries having no
duplicates or entries whose duplicates may be grouped
64
1.64
Aggregate Functions
65
1.65
Aggregate Functions (continued)
66
1.66
Aggregate Functions (continued)
67
1.67
Aggregate Functions (continued)
68
1.68
Aggregate Functions (continued)
69
1.69
Grouping Data
70
1.70
Grouping Data (continued)
71
1.71
Grouping Data (continued)
72
1.72
Virtual Tables: Creating a View
73
1.73
Virtual Tables: Creating a View
(continued)
74
1.74
Joining Database Tables
75
1.75
Joining Tables with an Alias
76
1.76
Summary
77
1.77
Summary (continued)
79
1.79
Summary (continued)
Aggregate functions
80
1.80
Summary (continued)
Natural join uses join condition to match only rows with equal values
in specified columns
Right outer join and left outer join used to select rows that have no
matching values in other related table
81
1.81