27
Chapter 14 Getting to First Base: Introduction to Database Concepts

Chapter 14 Getting to First Base: Introduction to Database Concepts

  • View
    224

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Chapter 14 Getting to First Base: Introduction to Database Concepts

Chapter 14

Getting to First Base:Introduction to Database Concepts

Page 2: Chapter 14 Getting to First Base: Introduction to Database Concepts

Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 14-2

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

Page 3: Chapter 14 Getting to First Base: Introduction to Database Concepts

Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 14-3

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

Page 4: Chapter 14 Getting to First Base: Introduction to Database Concepts

Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 14-4

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

Page 5: Chapter 14 Getting to First Base: Introduction to Database Concepts

Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 14-5

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

Page 6: Chapter 14 Getting to First Base: Introduction to Database Concepts

Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 14-6

Page 7: Chapter 14 Getting to First Base: Introduction to Database Concepts

Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 14-7

Page 8: Chapter 14 Getting to First Base: Introduction to Database Concepts

Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 14-8

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

Page 9: Chapter 14 Getting to First Base: Introduction to Database Concepts

Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 14-9

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

Page 10: Chapter 14 Getting to First Base: Introduction to Database Concepts

Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 14-10

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

Page 11: Chapter 14 Getting to First Base: Introduction to Database Concepts

Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 14-11

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

Page 12: Chapter 14 Getting to First Base: Introduction to Database Concepts

Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 14-12

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

Page 13: Chapter 14 Getting to First Base: Introduction to Database Concepts

Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 14-13

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

Page 14: Chapter 14 Getting to First Base: Introduction to Database Concepts

Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 14-14

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

Page 15: Chapter 14 Getting to First Base: Introduction to Database Concepts

Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 14-15

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

Page 16: Chapter 14 Getting to First Base: Introduction to Database Concepts

Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 14-16

Page 17: Chapter 14 Getting to First Base: Introduction to Database Concepts

Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 14-17

Page 18: Chapter 14 Getting to First Base: Introduction to Database Concepts

Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 14-18

Page 19: Chapter 14 Getting to First Base: Introduction to Database Concepts

Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 14-19

Page 20: Chapter 14 Getting to First Base: Introduction to Database Concepts

Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 14-20

Page 21: Chapter 14 Getting to First Base: Introduction to Database Concepts

Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 14-21

Page 22: Chapter 14 Getting to First Base: Introduction to Database Concepts

Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 14-22

Page 23: Chapter 14 Getting to First Base: Introduction to Database Concepts

Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 14-23

Page 24: Chapter 14 Getting to First Base: Introduction to Database Concepts

Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 14-24

Page 25: Chapter 14 Getting to First Base: Introduction to Database Concepts

Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 14-25

Page 26: Chapter 14 Getting to First Base: Introduction to Database Concepts

Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 14-26

Page 27: Chapter 14 Getting to First Base: Introduction to Database Concepts

Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 14-27