Docsity

Understanding Databases: Structure and Operations - Prof. Leona Mcmillan, Study notes of Computer Science

Partial preview of the text

Download Understanding Databases: Structure and Operations - Prof. Leona Mcmillan and more Study notes Computer Science in PDF only on Docsity!

Databases

Not All Tables Are Created Equal

• Spreadsheets use tables to store

data and formulas associated with

that data

• The “meaning” of data is implicit

• Row and column labels are essentially

for decoration, they are not actually

linked to the data

• Spreadsheet tables lack the necessary

structure to relate entries in one table

to entries in another

Relational Databases

• Specialized tables that describe relationships

between data items

• Relate the contents of one or more tables

• Based on

– Properties that are common between tables

– Items that are in common

• This “structure” allows us to filter and compose

data efficiently

Logical Data Model

• Entities - tables of anything that can be identified by

some number of characteristics, called attributes.

• Attributes have names and values , and these “values” are

what is actually stored in a database’s table.

• Relationships are defined between entities (tables)

Santa Cruz 966 846

Tower 14 76

Fernandina 642 1494

Isabela 4588 1707

Name Area Elevation

Island

Entity

Attributes

Entity Instance

Entity Relationship Diagram

• Relationships between entities (tables) can be

1-to-many (A department has many faculty)

• There is usually a table for each entity with a

1-to-many relationship

Department has Faculty

Relationships

• One-to-one: There is one instructor per class

• One-to-many: A department has many faculty

members

• Many-to-many: Each student takes several

classes, and each class has a list of students

Student

takes

Class

has

Implies a special table

Database Operations

• Select - extracts rows from one table to create a

new table. Select From

Ex: Select Lat < 40 and NS = ‘N’ From Nations

Nations

Brazil Brasilia 15 S 48 W

Japan Tokyo 35 N 143 E

Italy Rome 42 N 12 E

Israel Jerusalem 32 N 35 E

Ireland Dublin 52 N 7 W

Name Capital Lat NS Long EW

Database Operations

• Project - extracts columns from one table to

create a new table. Select From

Ex: Project Name, Capital From Nations

Nations

Brazil Brasilia 15 S 48 W

Japan Tokyo 35 N 143 E

Italy Rome 42 N 12 E

Israel Jerusalem 32 N 35 E

Ireland Dublin 52 N 7 W

Name Capital Lat NS Long EW

Database Operations

• Product for Combining tables

Ex: Select NS = “N” From Nations x NationStats

Nations

Brazil Brasilia 15 S 48 W

Japan Tokyo 35 N 143 E

Italy Rome 42 N 12 E

Israel Jerusalem 32 N 35 E

Ireland Dublin 52 N 7 W

Name Capital Lat NS Long EW

Area

Japan 127433494

USA 30361700

Brazil 18388841

Name Pop

NationStats

Product Result

Name Capital Lat NS Long EW Name Area Pop

  • Ireland Dublin 52 N 7 W Japan
  • Israel Jerusalem 32 N 35 E Japan
  • Italy Rome 42 N 12 E Japan
  • Japan Tokyo 35 N 143 E Japan
  • Brazil Brasilia 15 S 48 W Japan
  • Ireland Dublin 52 N 7 W USA
  • Israel Jerusalem 32 N 35 E USA
  • Italy Rome 42 N 12 E USA
  • Japan Tokyo 35 N 143 E USA
  • Brazil Brasilia 15 S 48 W USA
  • Ireland Dublin 52 N 7 W Brazil
  • Israel Jerusalem 32 N 35 E Brazil
  • Italy Rome 42 N 12 E Brazil
  • Japan Tokyo 35 N 143 E Brazil
  • Brazil Brasilia 15 S 48 W Brazil

One More Database Operation

• Join: also combines two tables, but only where the

specified attributes match

• Result = Join Nations, NationStats On

Nations.Name = NationStats.Name

Japan Tokyo 35 N 143 E 145883 127433494

Brazil Brasilia 15 S 48 W 3287597 18388841

Name Capital Lat NS Long EW Area Pop

Result

Database Operations

• Database operations can be composed

Ex: Project Name, Capital From

(Select NS = “N” From Nations)

Nations

Brasil Brasilia 15 S 48 W

Japan Tokyo 35 N 143 E

Italy Rome 42 N 12 E

Israel Jerusalem 32 N 35 E

Ireland Dublin 52 N 7 W

Name Capital Lat NS Long EW