Databases. Not All Tables Are Created Equal Spreadsheets use tables to store data and formulas...

18
Databases

Transcript of Databases. Not All Tables Are Created Equal Spreadsheets use tables to store data and formulas...

Databases

Not All Tables Are Created Equal

• Spreadsheets use tables to storedata and formulas associated withthat data

• The “meaning” of data is implicit• Row and column labels are essentially

for decoration, they are not actuallylinked to the data

• Spreadsheet tables lack the necessarystructure to relate entries in one tableto entries in another

Databases

• Structured collections of data• Indexed and organized• In contrast to

– Files (unstructured)– Spreadsheets

(structure but no semantic (meaningful) indexing)

Relational Databases

• Specialized tables that describe relationshipsbetween 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 composedata 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)

Database Properties

• Instances are unordered. There is no inherentorder to the rows and columns of a table

• Uniqueness. Each instance (row) must be unique• Keys. Some subset of attributes (columns)

distinguishes each instance in the table. Theremay be several distinct subsets that distinguishinstances; each is a candidate key. Becausedatabases usually have several candidate keys,we choose one and call it the primary key.

Entity Relationship Diagram

• Relationships between entities (tables) can be1-to-many (A department has many faculty)

• There is usually a table for each entity with a1-to-many relationship

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

A Database’s Schema

• The combination of table attributes and relations specify the structure of a database

• This structure is called the database’s schema• A schema can be specified for an empty

database

Database Operations

• Select - extracts rows from one table to create a new table. Select <Test> From <Table>

Database Operations

• Project - extracts columns from one table tocreate a new table. Select <Fields> From <Table>

Database Operations

• Database operations can be composed

Database Operations

• Product for Combining tables

Product Result

Using Database Products

• Usually table products would be combined with a series of Select and Project operations

• Most often, products would combine tables that do not share common attributes

One More Database Operation

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

• Result = Join Nations, NationStats OnNations.Name = NationStats.Name

Database Operations

• Database operations can be composed

Summary

• Databases are specialized tables with names andattributes for all entities

• In a relational database, there exist relationsbetween tables

• The combination of a tables attributes andrelations between the tables in a datbasecomprise it’s schema

• Databases provide basic operations including-Select, Project, Product, Join