Chapter 14
Getting to
First Base:
Introduction to
Database Concepts
Tables: Special Kinds Of Lists
• A database (DB) stores data
• A relational database stores data in tables
and describes the relationships among the
different kinds of data
• Databaspecifys are like the lists in
spreadsheets, but with added constraints
– Constraints limit the kinds of data they can
contain, but expand the operations they can
perform
Copyright © 2006 Pearson Addison-Wesley. All rights reserved.
14-2
Entities
• Anything that can de identified by a fixed
number of its characteristics (attributes)
– Attributes have names and values
– The values are the data that's stored in the table
• To create a table, we specify the entity's
name (table name), the names of the entity's
attributes, and the kinds of values each
attribute can have
Copyright © 2006 Pearson Addison-Wesley. All rights reserved.
14-3
Properties of Entities
• Table Instances:
– Table is initially empty. It has a name and
column headings (the attribute names) but
no rows
– Each row will represent an entity
– An instance of the database table is the
table with a specific set of rows
Copyright © 2006 Pearson Addison-Wesley. All rights reserved.
14-4
Properties Of Entities (Cont'd)
• Structure: Content and Metadata
– We separate the structure of the information from
the information itself
– A table's metadata includes its name, its attributes'
names, the types of values each attribute can
have, and the primary key, at a minimum
– Some properties are not metadata:
order of rows and columns is unimportant
Copyright © 2006 Pearson Addison-Wesley. All rights reserved.
14-5
Copyright © 2006 Pearson Addison-Wesley. All rights reserved.
14-6
Copyright © 2006 Pearson Addison-Wesley. All rights reserved.
14-7
Properties Of Entities (cont'd)
• Entities and Uniqueness
– A database table doesn't have any
duplicate rows
– There must be at least one distinguishing
characteristic to each entity
– Some characteristics may be the same, but
not all
Copyright © 2006 Pearson Addison-Wesley. All rights reserved.
14-8
Properties Of Entities (cont'd)
• Keys
– Any set of attributes for which all attributes are
different is a candidate key
– Pick one and call it the primary key
– Key must distinguish all potential and actual
entities, not just those that happen to be in the
table at a given times
– If no combination of attributes qualify as a
candidate key, assign a unique ID to each entity
• Like a student ID number issued by school
Copyright © 2006 Pearson Addison-Wesley. All rights reserved.
14-9
Operations on Tables
• Main use of database is to look up
information
– Users specify what they want to know, and
the database finds it
• Five fundamental operations that can be
performed on tables: Select, Project,
Union, Difference, Product
Copyright © 2006 Pearson Addison-Wesley. All rights reserved.
14-10
Operations (cont'd)
• Select Operation
– Takes rows from one table to create a new table
• Specify the table from which rows are to be taken, and
the test for selection
• Syntax: Select Test From Table
• Test is applied to each rows of the table to determine
if it should be included in result table
• Test uses attribute names, constants and
relational operators
• If the test is true for a given row, the row is included in
the result table; otherwise it is ignored
Copyright © 2006 Pearson Addison-Wesley. All rights reserved.
14-11
Operations (cont'd)
• Project Operation
– Builds a new table from the columns of an
existing table
– Specify name of exiting table (or tables) and
the columns (field names) to be included in the new table
– Syntax:
• Project Field_List From Table
– The new table will have the number of columns specified,
and the same number of rows as the original table, unless
• The new table eliminates a key field. If rows duplicate in the
new table, duplicates will be eliminated
Copyright © 2006 Pearson Addison-Wesley. All rights reserved.
14-12
Operations (cont'd)
• Union Operation
– Combines two tables (that have the same attributes)
– Syntax:
• Table1 + Table2
• Difference Operation
– Remove from one table the rows also listed in a
second table
– Syntax:
• Table1 - Table2
• Product Operation
– Creates a super table with all fields from both tables
– Puts the rows together
– Syntax:
• Table1 Table2
Copyright © 2006 Pearson Addison-Wesley. All rights reserved.
14-13
Join Operation
• Combines two tables, like the Product
Operation, but doesn't necessarily
produce all pairings
– If the two tables each have fields with a
common data type, new table combines
only the rows from the given tables that
match on the fields
– Syntax:
• Table1 Table2 On Match
Copyright © 2006 Pearson Addison-Wesley. All rights reserved.
14-14
Join Operation (cont'd)
• Match is a comparison test involving a
field from each table
• If the same field in table 1 contains the
same data in the row for that field
Copyright © 2006 Pearson Addison-Wesley. All rights reserved.
14-15
Copyright © 2006 Pearson Addison-Wesley. All rights reserved.
14-16
Copyright © 2006 Pearson Addison-Wesley. All rights reserved.
14-17
Copyright © 2006 Pearson Addison-Wesley. All rights reserved.
14-18
Copyright © 2006 Pearson Addison-Wesley. All rights reserved.
14-19
Copyright © 2006 Pearson Addison-Wesley. All rights reserved.
14-20
Copyright © 2006 Pearson Addison-Wesley. All rights reserved.
14-21
Copyright © 2006 Pearson Addison-Wesley. All rights reserved.
14-22
Copyright © 2006 Pearson Addison-Wesley. All rights reserved.
14-23
Copyright © 2006 Pearson Addison-Wesley. All rights reserved.
14-24
Copyright © 2006 Pearson Addison-Wesley. All rights reserved.
14-25
Copyright © 2006 Pearson Addison-Wesley. All rights reserved.
14-26
Copyright © 2006 Pearson Addison-Wesley. All rights reserved.
14-27