DATABASE SYSTEM.

Slides:



Advertisements
Similar presentations
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
Advertisements

CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 28 Database Systems I The Relational Data Model.
Chapter 3 The Relational Model Transparencies © Pearson Education Limited 1995, 2005.
The Relational Model CS 186, Spring 2006, Lecture 2 R & G, Chap. 1 & 3.
Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables.
1 Relational Model. 2 Relational Database: Definitions  Relational database: a set of relations  Relation: made up of 2 parts: – Instance : a table,
1 Minggu 2, Pertemuan 3 The Relational Model Matakuliah: T0206-Sistem Basisdata Tahun: 2005 Versi: 1.0/0.0.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 3 The Relational Database Model.
1 Pertemuan 04 MODEL RELASIONAL Matakuliah: >/ > Tahun: > Versi: >
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 3 The Relational Database Model.
Relational Database Management System A type of database in which records are stored in relational form is called relational database management system.
Database Architecture The Relational Database Model.
The Relational Database Model
CSC271 Database Systems Lecture # 6. Summary: Previous Lecture  Relational model terminology  Mathematical relations  Database relations  Properties.
Lecture 2 The Relational Model. Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical relations.
Chapter 4 The Relational Model Pearson Education © 2014.
© Pearson Education Limited, Chapter 2 The Relational Model Transparencies.
The Relational Model These slides are based on the slides of your text book.
Relational Model Session 6 Course Name: Database System Year : 2012.
Chapter 4 The Relational Model.
Chapter 3 The Relational Model Transparencies Last Updated: Pebruari 2011 By M. Arief
Data Models Amandeep Kaur Lecturer GPC Khunimajra Call at
Relational Data Model, R. Ramakrishnan and J. Gehrke with Dr. Eick’s additions 1 The Relational Model Chapter 3.
The Relational Model. Review Why use a DBMS? OS provides RAM and disk.
Chapter 3 The Relational Model. 2 Chapter 3 - Objectives u Terminology of relational model. u How tables are used to represent data. u Connection between.
1 The Relational Database Model. 2 Learning Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical.
9/7/2012ISC329 Isabelle Bichindaritz1 The Relational Database Model.
1 The Relational Model. 2 Why Study the Relational Model? v Most widely used model. – Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. v “Legacy.
FALL 2004CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
The Relational Model Pertemuan 03 Matakuliah: M0564 /Pengantar Sistem Basis Data Tahun : 2008.
Relational Database. Database Management System (DBMS)
Module Coordinator Tan Szu Tak School of Information and Communication Technology, Politeknik Brunei Semester
Database Systems, 9th Edition 1.  In this chapter, students will learn: That the relational database model offers a logical view of data About the relational.
Database Systems: Design, Implementation, and Management Tenth Edition Chapter 3 The Relational Database Model.
Database Systems: Design, Implementation, and Management Ninth Edition Chapter 3 The Relational Database Model.
12/2/2015CPSC , CPSC , Lecture 41 Relational Model.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 3 The Relational Database Model.
Department of Mathematics Computer and Information Science1 CS 351: Database Systems Christopher I. G. Lanclos Chapter 3: The Relational Database Model.
The Relational Model. 2 Relational Model Terminology u A relation is a table with columns and rows. –Only applies to logical structure of the database,
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 3 The Relational Database Model.
Chapter 3 The Relational Database Model. Database Systems, 10th Edition 2 * Relational model * View data logically rather than physically * Table * Structural.
The Relational Model © Pearson Education Limited 1995, 2005 Bayu Adhi Tama, M.T.I.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 3 The Relational Database Model.
CSCI 6315 Applied Database Systems Review for Midterm Exam I Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
Chapter 3 The Relational Model. Objectives u Terminology of relational model. u How tables are used to represent data. u Connection between mathematical.
Chapter 4 The Relational Model Pearson Education © 2009.
LECTURE TWO Introduction to Databases: Data models Relational database concepts Introduction to DDL & DML.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
COP Introduction to Database Structures
The Relational Database Model
Database Systems: Design, Implementation, and Management Tenth Edition
Chapter 4 Relational Model Characteristics
Lecture 2 The Relational Model
The Relational Database Model
Data Base System Lecture 6: Relational Model
Chapter 4 The Relational Model Pearson Education © 2009.
The Relational Model Relational Data Model
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
Database Systems: Design, Implementation, and Management Ninth Edition
The Relational Model Transparencies
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
The Relational Database Model
Design tools and techniques for a relational database system
Chapter 4 The Relational Model Pearson Education © 2009.
Database Systems: Design, Implementation, and Management
Views Base Relation View
Presentation transcript:

DATABASE SYSTEM

Database Relational Model Chapter 2 History of relationship model Structure of data relationship Database Scheme Mathematic Relationship: Algebra, Calculus

Data Models A Database models some portion of the real world. Data Model is link between user’s view of the world and bits stored in computer. Many models have been proposed. Student (sid: string, name: string, login: string, age: integer, gpa:real) 1010111101 3

Describing Data: Data Models A data model is a collection of concepts for describing data. A database schema is a description of a particular collection of data, using a given data model. The relational model of data is the most widely used model today. Main concept: relation, basically a table with rows and columns. Every relation has a schema, which describes the columns, or fields. 5 4

Levels of Abstraction Users DB Physical Schema Conceptual Schema Views describe how users see the data. Conceptual schema defines logical structure Physical schema describes the files and indexes used. (sometimes called the ANSI/SPARC model) Physical Schema Conceptual Schema View 1 View 2 View 3 DB 6 5

Data Independence:The Big Breakthrough of the Relational Model A Simple Idea: Applications should be insulated from how data is structured and stored. Physical Schema Conceptual Schema View 1 View 2 View 3 DB Logical data independence: Protection from changes in logical structure of data. Physical data independence: Protection from changes in physical structure of data. 6

Why Study the Relational Model? Most widely used model currently. DB2, MySQL, Oracle, PostgreSQL, SQLServer, … Note: some “Legacy systems” use older models e.g., IBM’s IMS Object-oriented concepts have recently merged in object-relational model Informix, IBM DB2, Oracle 8i Early work done in POSTGRES research project at Berkeley XML (semi-structured)models emerging? 7

Relational Database: Definitions Relational database: a set of relations. Relation: made up of 2 parts: Schema : specifies name of relation, plus name and type of each column. E.g. Students(sid: string, name: string, login: string, age: integer, gpa: real) Instance : a table, with rows and columns. #rows = cardinality #fields = degree / arity Can think of a relation as a set of rows or tuples. i.e., all rows are distinct 8

Example: University Database Conceptual schema: Students(sid: string, name: string, login: string, age: integer, gpa:real) Courses(cid: string, cname:string, credits:integer) Enrolled(sid:string, cid:string, grade:string) External Schema (View): Course_info(cid:string,enrollment:integer) One possible Physical schema : Relations stored as unordered files. Index on first column of Students. Physical Schema Conceptual Schema View 1 View 2 View 3 DB 7 9

Relational Model Terminology A relation is a table with columns and rows. Only applies to logical structure of the database, not the physical structure. Attribute is a named column of a relation. Domain is the set of allowable values for one or more attributes.

Relational Model Terminology Tuple is a row of a relation. Degree is the number of attributes in a relation. Cardinality is the number of tuples in a relation. Relational Database is a collection of normalized relations with distinct relation names.

Instances of Branch and Staff Relations

Examples of Attribute Domains

Alternative Terminology for Relational Model

A Logical View of Data Relational model Table View data logically rather than physically Table Structural and data independence Resembles a file conceptually Relational database model is easier to understand than hierarchical and network models 15

Tables and Their Characteristics Logical view of relational database is based on relation Relation thought of as a table Table: two-dimensional structure composed of rows and columns Persistent representation of logical relation Contains group of related entities (entity set) 16

17

18

Keys Keys are a way to associate tuples in different relations Keys are one form of integrity constraint (IC) Enrolled Students PRIMARY Key FORIEGN Key 19

Primary Keys A set of fields is a superkey if: No two distinct tuples can have same values in all key fields A set of fields is a candidate key for a relation if : It is a superkey No subset of the fields is a superkey what if >1 key for a relation? one of the candidate keys is chosen (by DBA) to be the primary key. E.g. sid is a key for Students. What about name? The set {sid, gpa} is a superkey. 20

Primary and Candidate Keys in SQL Possibly many candidate keys (specified using UNIQUE), one of which is chosen as the primary key. Keys must be used carefully! “For a given student and course, there is a single grade.” CREATE TABLE Enrolled (sid CHAR(20) cid CHAR(20), grade CHAR(2), PRIMARY KEY (sid,cid)) PRIMARY KEY (sid), UNIQUE (cid, grade)) vs. “Students can take only one course, and no two students in a course receive the same grade.” 21

Foreign Keys, Referential Integrity Foreign key : Set of fields in one relation that is used to `refer’ to a tuple in another relation. Must correspond to the primary key of the other relation. Like a `logical pointer’. If all foreign key constraints are enforced, referential integrity is achieved (i.e., no dangling references.) 22

Foreign Keys in SQL CREATE TABLE Enrolled E.g. Only students listed in the Students relation should be allowed to enroll for courses. sid is a foreign key referring to Students: CREATE TABLE Enrolled (sid CHAR(20),cid CHAR(20),grade CHAR(2), PRIMARY KEY (sid,cid), FOREIGN KEY (sid) REFERENCES Students ) Enrolled Students 11111 English102 A 23

Keys Each row in a table must be uniquely identifiable Key is one or more attributes that determine other attributes Key’s role is based on determination If you know the value of attribute A, you can determine the value of attribute B Functional dependence Attribute B is functionally dependent on A if all rows in table that agree in value for A also agree in value for B 24

25

Keys (cont’d.) Primary key Composite key Key attribute Superkey Candidate key selected to identify tuples uniquely within relation. Composite key Composed of more than one attribute Key attribute Any attribute that is part of a key Superkey Any key that uniquely identifies a tuple within a relation. Candidate key A superkey such that no proper subset is a superkey within the relation 26

Keys (cont’d.) Nulls No data entry Not permitted in primary key Should be avoided in other attributes Can represent: An unknown attribute value A known, but missing, attribute value A “not applicable” condition 27

Keys (cont’d.) Nulls (cont’d.) Can create problems when functions such as COUNT, AVERAGE, and SUM are used Can create logical problems when relational tables are linked 28

Keys (cont’d.) Controlled redundancy Makes the relational database work Tables within the database share common attributes Enables tables to be linked together Multiple occurrences of values not redundant when required to make the relationship work Redundancy exists only when there is unnecessary duplication of attribute values 29

30

31

Keys (cont’d.) Foreign key (FK) Referential integrity Secondary key An attribute whose values match primary key values in the related table Referential integrity FK contains a value that refers to an existing valid tuple (row) in another relation Secondary key Key used strictly for data retrieval purposes 32

33

Integrity Rules Many RDBMs enforce integrity rules automatically Safer to ensure that application design conforms to entity and referential integrity rules Designers use flags to avoid nulls Flags indicate absence of some value 34

35

Database Relations Relation schema Relational database schema Named relation defined by a set of attribute and domain name pairs. Let A1, A2… An be attributes of domains D1, D2, … Dn Then set {A1 : D1, A2: D2,… An:Dn} Ex : {(branchNo: B005, street: 22 Deer Rd, city: London)} Relational database schema Set of relation schemas, each with a distinct name. If R1, R2, … Rn are set of relation schemas, then the relational database schema, R as R={R1, R2,… Rn}

Properties of Relations Relation name is distinct from all other relation names in relational schema. Each cell of relation contains exactly one atomic (single) value. Each attribute has a distinct name. Values of an attribute are all from the same domain.

Properties of Relations Each tuple is distinct; there are no duplicate tuples. Order of attributes has no significance. Order of tuples has no significance, theoretically.

Relational Keys Superkey Candidate Key An attribute, or set of attributes, that uniquely identifies a tuple within a relation. Candidate Key Superkey (K) such that no proper subset is a superkey within the relation. A candidate key (K) for a relation (R) has 2 properties: In each tuple of R, values of K uniquely identify that tuple (uniqueness). No proper subset of K has the uniqueness property (irreducibility).

Relational Keys Primary Key Alternate Keys Foreign Key Candidate key selected to identify tuples uniquely within relation. Alternate Keys Candidate keys that are not selected to be primary key. Foreign Key Attribute, or set of attributes, within one relation that matches candidate key of some (possibly same) relation.

Integrity Constraints Null Represents value for an attribute that is currently unknown or not applicable for tuple. Deals with incomplete or exceptional data. Represents the absence of a value and is not the same as zero or spaces, which are values.

Integrity Constraints Entity Integrity In a base relation, no attribute of a primary key can be null. Referential Integrity If foreign key exists in a relation, either foreign key value must match a candidate key value of some tuple in its home relation or foreign key value must be wholly null.

Integrity Constraints General Constraints Additional rules specified by users or database administrators that define or constrain some aspect of the enterprise.

Views Base Relation View Named relation corresponding to an entity in conceptual schema, whose tuples are physically stored in database. View Dynamic result of one or more relational operations operating on base relations to produce another relation.

Views A virtual relation that does not necessarily actually exist in the database but is produced upon request, at time of request. Contents of a view are defined as a query on one or more base relations. Views are dynamic, meaning that changes made to base relations that affect view attributes are immediately reflected in the view.

Purpose of Views Provides powerful and flexible security mechanism by hiding parts of database from certain users. Permits users to access data in a customized way, so that same data can be seen by different users in different ways, at same time. Can simplify complex operations on base relations.

Updating Views All updates to a base relation should be immediately reflected in all views that reference that base relation. If view is updated, underlying base relation should reflect change. Pearson Education © 2009

Updating Views There are restrictions on types of modifications that can be made through views: Updates are allowed if query involves a single base relation and contains a candidate key of base relation. Updates are not allowed involving multiple base relations. Updates are not allowed involving aggregation or grouping operations. Pearson Education © 2009

Updating Views Classes of views are defined as: theoretically not updateable; theoretically updateable; partially updateable. Pearson Education © 2009