Top Banner
Lecture 3 The Relational DB Model
22

Lecture 3 The Relational DB Model. Learning Objectives That the relational database model takes a logical view of data That the relational model’s basic.

Dec 27, 2015

Download

Documents

Sybil Watson
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Lecture 3 The Relational DB Model. Learning Objectives That the relational database model takes a logical view of data That the relational model’s basic.

Lecture 3

The Relational DB Model

Page 2: Lecture 3 The Relational DB Model. Learning Objectives That the relational database model takes a logical view of data That the relational model’s basic.

Learning Objectives

• That the relational database model takes a logical view of data

• That the relational model’s basic components are entities, attributes, and relationships among entities

• How entities and their attributes are organized into tables• About relational database operators, the data dictionary,

and the system catalog• How data redundancy is handled in the relational

database model• Why indexing is important

Page 3: Lecture 3 The Relational DB Model. Learning Objectives That the relational database model takes a logical view of data That the relational model’s basic.

Oracle log on procedures

• Can log from home

• Download putty shell

http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

Page 4: Lecture 3 The Relational DB Model. Learning Objectives That the relational database model takes a logical view of data That the relational model’s basic.

Two steps

• Log on to UNIX

• Log on to ORACLE

To change ORACLE Password:

Sql> ALTER USER username IDENTIFIED BY newpassword;

Page 5: Lecture 3 The Relational DB Model. Learning Objectives That the relational database model takes a logical view of data That the relational model’s basic.

to get information on your table:sql> DESC tablename

to get a list of your tables:Sql> SELECT TABLE_NAME FROM

USER_TABLES;

To saveSql> commit;

To unsaveSql> rollback;

Page 6: Lecture 3 The Relational DB Model. Learning Objectives That the relational database model takes a logical view of data That the relational model’s basic.

Scope of SQL

DDL statements:• Sql>Create• Sql>Drop • Sql>AlterDML statements• Sql>Select• Sql>Update• Sql>Delete• Sql>Insert

Page 7: Lecture 3 The Relational DB Model. Learning Objectives That the relational database model takes a logical view of data That the relational model’s basic.

Creating DB Structure

Steps• create SCHEMA

(already done for you)• create TABLES

– FK & PK

• create VIEWS• create indexes

Page 8: Lecture 3 The Relational DB Model. Learning Objectives That the relational database model takes a logical view of data That the relational model’s basic.

Relational table

• Two Dim structure• Order of rows is NOT important• Cols represent attributes• Row represent an occurrence of an entity• Each column has a set of allowable values,

called domain• Each table has a primary key• Intersection of row/column represent a single

value

Page 9: Lecture 3 The Relational DB Model. Learning Objectives That the relational database model takes a logical view of data That the relational model’s basic.

Data Structure & Data Types

Data Structure:• Domain• Relationship• relational DB• Keys (PK & FK)

Data Type:• Numeric/Character• Date• Logical• Pictures• Graphical

Page 10: Lecture 3 The Relational DB Model. Learning Objectives That the relational database model takes a logical view of data That the relational model’s basic.

Relation

• Relation is a table of n columns and m rows., Referred to as: m x n

• rows define CARDINALITY (m), cols define DEGREE (n)

• relations are represented as:• relation (attribute names..)• ex;• STUDENT (student name, student ss#, student

address, GPA)

Page 11: Lecture 3 The Relational DB Model. Learning Objectives That the relational database model takes a logical view of data That the relational model’s basic.

Relational DB

• a collection of relations

Keys

• Primary

• Candidate

• Foreign

• Secondary

Page 12: Lecture 3 The Relational DB Model. Learning Objectives That the relational database model takes a logical view of data That the relational model’s basic.

Primary Key (PK) (page 66)

a unique identifier guarantees that each row of a relation can be uniquely addressed, in other words, if I give you the value of a primary key ,we should get one and only one tuple (row) from the table. It is usually a field from the table or a combination of fields (also called concatenated or composite key) from the table.

Page 13: Lecture 3 The Relational DB Model. Learning Objectives That the relational database model takes a logical view of data That the relational model’s basic.

Foreign key

• Relates two tables

• An attribute in ONE table which relates PK in another table

• Candidate key

• Secondary key

Page 14: Lecture 3 The Relational DB Model. Learning Objectives That the relational database model takes a logical view of data That the relational model’s basic.

Functional dependency

A-- B

(A , B)-- C

Page 15: Lecture 3 The Relational DB Model. Learning Objectives That the relational database model takes a logical view of data That the relational model’s basic.

Integrity Rules

• Entity integrity

• Referential integrity

Page 16: Lecture 3 The Relational DB Model. Learning Objectives That the relational database model takes a logical view of data That the relational model’s basic.

Relational Algebra (p 72 & p298)

Union compatible

Operations

• Union

• Difference

• Intersect

Page 17: Lecture 3 The Relational DB Model. Learning Objectives That the relational database model takes a logical view of data That the relational model’s basic.

Relationship among databases

• 1:1

• 1:m

• M:n

• recursive

Page 18: Lecture 3 The Relational DB Model. Learning Objectives That the relational database model takes a logical view of data That the relational model’s basic.

ER Diagrams and their conversion to relations

• 1:1

• 1:m

• M:n

Page 19: Lecture 3 The Relational DB Model. Learning Objectives That the relational database model takes a logical view of data That the relational model’s basic.

The Data Dictionary and System Catalog (page 78)

• Data dictionary – Used to provide detailed accounting of all tables

found within the user/designer-created database– Contains (at least) all the attribute names and

characteristics for each table in the system– Contains metadata—data about data– Sometimes described as “the database

designer’s database” because it records the design decisions about tables and their structures

Page 20: Lecture 3 The Relational DB Model. Learning Objectives That the relational database model takes a logical view of data That the relational model’s basic.

The Data Dictionary

and the System Catalog (continued)

System catalog

– Contains metadata

– Detailed system data dictionary that describes all objects within the database

– Terms “system catalog” and “data dictionary” are often used interchangeably

– Can be queried just like any user/designer-created table

Page 21: Lecture 3 The Relational DB Model. Learning Objectives That the relational database model takes a logical view of data That the relational model’s basic.

Indexes

• Unique

• Non-unique

• Index points to the records in the table

Page 22: Lecture 3 The Relational DB Model. Learning Objectives That the relational database model takes a logical view of data That the relational model’s basic.

• Q1,4, 5 and 6/p96