what did we cover in the last class?

12
What did we cover in the last What did we cover in the last class? class? Can’t escape databases at this point in time! DBMS versus databases Databases versus File Systems Transactions, query processing ACID properties Data Models

Upload: arvin

Post on 07-Jan-2016

33 views

Category:

Documents


1 download

DESCRIPTION

What did we cover in the last class?. Can ’ t escape databases at this point in time! DBMS versus databases Databases versus File Systems Transactions, query processing ACID properties Data Models. Chapter 2: Relational Models. Models - again. What is a model? Relational model - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: What did we cover in the last class?

What did we cover in the last class?What did we cover in the last class?

Can’t escape databases at this point in time!

DBMS versus databases

Databases versus File Systems

Transactions, query processing

ACID properties

Data Models

Page 2: What did we cover in the last class?

Chapter 2: Relational ModelsChapter 2: Relational Models

Page 3: What did we cover in the last class?

Models - againModels - again

What is a model?

Relational model

Other ways:

Hierarchies

Networks

Objects (object oriented, XML)

Entities and their relationships (E-R).

Entities, relationships, constraints.

E-R Model Relational Model

Page 4: What did we cover in the last class?
Page 5: What did we cover in the last class?

Relational ModelRelational Model

Terminology

Relations

Tuples

Attributes

Domains

Schema

Instances

Keys

Order independence: tuples, attributes

Data Types: CHAR, VARCHAR, …., DATE, TIME, etc….

Logical level – [not a physical data structure]

Page 6: What did we cover in the last class?

Example SchemaExample Schema

Product(maker, model, type)

PC(model, speed, ram, hd, price)

Laptop(model, speed, ram, hd, screen, price)

Printer(model, color, type, price)

Classes(class, type, country, numGuns, bore, displacement)

Ships(name, class, launched)

Battles(name, data)

Outcomes(ship, battle, result)

Page 7: What did we cover in the last class?
Page 8: What did we cover in the last class?

SQL: Data DefinitionSQL: Data Definition

An SQL relation is defined using the create table command:

create table r (A1 D1, A2 D2, ..., An Dn,(integrity-constraint1),...,(integrity-constraintk))

r is the name of the relation each Ai is an attribute name in the schema of relation r

Di is the data type of values in the domain of attribute Ai

Example:

create table Instructor ( ID char(5), name varchar(20) not null, dept_name varchar(20), salary numeric(8,2))

insert into instructor values (‘10211’, ’Smith’, ’Biology’, 66000); insert into instructor values (‘10211’, null, ’Biology’, 66000);

Page 9: What did we cover in the last class?

Integrity ConstraintsIntegrity Constraints

not null

primary key (A1, ..., An )

foreign key (Am, ..., An ) references r

Example: Declare ID as the primary key for instructor

create table Instructor ( ID char(5), name varchar(20) not null, dept_name varchar(20), salary numeric(8,2), primary key (ID))

primary key declaration on an attribute automatically ensures not null

Page 10: What did we cover in the last class?

Integrity ConstraintsIntegrity Constraints

create table Instructor ( ID char(5), name varchar(20) not null, dept_name varchar(20), salary numeric(8,2), primary key (ID), foreign key (dept_name) references department)

create table Department( dept_name varchar(20), num_instructors integer, num_students integer, primary key (dept_name))

Page 11: What did we cover in the last class?

Relational ModelRelational Model

Drop Relation

drop R (R: relation name)

drop department

Alter Relation

alter relation r add A D

A: attribute D: domain

– alter department add address varchar(30)

alter relation r drop A

alter department drop address

Schema, Instances Keys

Order independence: tuples, attributes

Data Types: CHAR, VARCHAR, …., DATE, TIME, etc….

Logical level – [not a physical data structure]

Page 12: What did we cover in the last class?

Next: Relational AlgebraNext: Relational Algebra

Select

Project

Union

Intersection

Subtraction

Other operators.