Академический Документы
Профессиональный Документы
Культура Документы
Objectives
! In this chapter you will:
! Consider the widespread use of databases ! Take a brief tour of database development history ! Learn basic database concepts ! Be introduced to popular database management software ! See how normalization makes your data more organized
Objectives (contd.)
! In this chapter you will (contd.):
! Explore the database design process ! Understand data relationships ! Gain an understanding of Structured Query Language (SQL) ! Learn some common SQL commands
Database Applications
! Database
! Data logically related and organized into a file or set of files to allow access and use
! Database applications
! Student grading and library inventory ! Genealogy studies and Social Security payments ! Real estate sales, video store rentals, and retail sales ! Space shuttle missions
! Database development
! Essential part of computer professionals daily life
Connecting with Computer Science, 2e 5
! 1978
! C. Wayne Ratliff of Martin Marietta develops Vulcan
Connecting with Computer Science, 2e 6
Database Concepts
! Basic database elements
! Database: collection of one or more tables (entities) ! Table or entity: divided into rows and columns ! Row (record or tuple): collection of columns ! Column (field or attribute): represents specific information ! Domain: set of possible column values
10
11
Indexes
! Special files occupying their own space
! Specify columns determining how information stored in a table can be accessed more efficiently
! Examples: music database and the telephone book
! Advantages
! Flexibility: many different columns to sort against ! Searching and retrieval speeds up
! Disadvantages
! Extra storage space ! Updating takes longer
Connecting with Computer Science, 2e 12
An Example of Indexing
13
14
Figure 6-3, Database records sorted by using the UPC column as a key
15
16
Normalization
! Set of rules dictating database design
! Eliminates duplication and inconsistencies ! Process: sequence of stages called normal forms
! Five normal forms ! Third normal form provides sufficient structure
17
18
Figure 6-6, Additional table columns can be gleaned from input forms
Connecting with Computer Science, 2e 20
21
23
! Creating 2NF
! Determine columns not dependent on PK
! Remove columns and place in new table
25
Figure 6-10, 2NF: Remove any columns that arent dependent on the composite primary key and create a new table
Connecting with Computer Science, 2e 26
27
28
29
32
33
! Normalizing databases
! Like cleaning a closet
35
36
37
! One-to-many (1:M)
38
40
41
! ER models
! Visual diagram composed of entities and relationships
! Entities represent the database tables ! Relationships show how tables relate to each other
! Cardinality
! Shows numeric relations between entities
Connecting with Computer Science, 2e 42
! Example:
! ER model for the student-grading system
Connecting with Computer Science, 2e 43
44
Step 6: Reevaluate
! Reevaluate database performance
! Ensure database meets all reporting and form needs ! Include the end users ! Explain each table and field being used ! Make sure fields are defined to users requirements ! Manipulate data structure with SQL commands
45
46
48
! Syntax:
49
50
! Syntax:
INSERT INTO table_name [(column1,column2, . . . )] VALUES (constant1, constant2, . . . )
51
Figure 6-19, SQL INSERT INTO statement to add a record to the Songs table and its result
Connecting with Computer Science, 2e 52
SELECT Statement
! Retrieves data from one or more tables ! Syntax:
53
Figure 6-20, SQL SELECT statement to return the name, media type, and track number for songs
Connecting with Computer Science, 2e 54
WHERE Clause
! Specifies additional criteria for retrieving data
! Fields should be included in fields selected
55
Figure 6-21, SQL SELECT statement with a WHERE clause and the results
Connecting with Computer Science, 2e 56
Figure 6-22, More descriptive SQL SELECT statement with a WHERE clause
Connecting with Computer Science, 2e 57
Figure 6-23, SQL SELECT statement with a WHERE clause and AND versus OR
Connecting with Computer Science, 2e 58
ORDER BY Clause
! Permits user to change how the data is returned
! Makes for a more meaningful presentation
! Default: data returned in sequential order ! User can specify the ORDER BY column name(s) ! Also returns data in ascending (default) or descending order
59
Figure 6-24, SQL SELECT statement with an ORDER BY clause and the results
Connecting with Computer Science, 2e 60
Figure 6-25, SQL SELECT statement, using an ORDER BY clause with the default ascending option
Connecting with Computer Science, 2e 61
Figure 6-26, SQL SELECT statement, using an ORDER BY clause with the DESC option
Connecting with Computer Science, 2e 62
63
! Database
! Powerful tool used in many areas
! Including business and computing
Connecting with Computer Science, 2e 64
Summary
! Database
! Collection of logically related records
! DBMS
! Software used to design, manage, and interface with databases
! Indexes
! Files that revise default sequential order of data
! Normalization
! Process of removing data redundancies
Connecting with Computer Science, 2e 65
Summary (contd.)
! Data is normalized with five normal forms
! First three normal forms most important
! Primary key
! Uniquely identifies table entries
! Foreign key
! Primary keys in other tables
66
Summary (contd.)
! 1:M and 1:1 notations indicate cardinality ! Six-step database design process ! Structured Query Language (SQL)
! Manipulates, defines, and administers data
67