Switch off your Mobiles Phones or Change Profile to Silent Mode.

Slides:



Advertisements
Similar presentations
The Relational Model and Relational Algebra Nothing is so practical as a good theory Kurt Lewin, 1945.
Advertisements

IS698: Database Management Min Song IS NJIT. The Relational Data Model.
Relational Algebra, Join and QBE Yong Choi School of Business CSUB, Bakersfield.
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
The Relational Database Model
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Basic (Flat) Relational Model.
Introduction to Structured Query Language (SQL)
Chapter 2 The Relational Database Model
The Relational Database Model
The Relational Database Model. 2 Objectives How relational database model takes a logical view of data Understand how the relational model’s basic components.
Introduction to Structured Query Language (SQL)
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 3 The Relational Database Model.
3 1 Chapter 3 The Relational Database Model Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
The Relational Model Codd (1970): based on set theory Relational model: represents the database as a collection of relations (a table of values --> file)
10/3/2000SIMS 257: Database Management -- Ray Larson Relational Algebra and Calculus University of California, Berkeley School of Information Management.
Database Constraints. Database constraints are restrictions on the contents of the database or on database operations Database constraints provide a way.
3 The Relational Model MIS 304 Winter Class Objectives That the relational database model takes a logical view of data That the relational model’s.
The Relational Database Model
Relational Model & Relational Algebra. 2 Relational Model u Terminology of relational model. u How tables are used to represent data. u Connection between.
Lecture 2 The Relational Model. Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical relations.
Module Title? DBMS E-R Model to Relational Model.
1 The Relational Data Model, Relational Constraints, and The Relational Algebra.
Switch off your Mobiles Phones or Change Profile to Silent Mode
Content Resource- Elamsari and Navathe, Fundamentals of Database Management systems.
Database. Basic Definitions Database: A collection of related data. Database Management System (DBMS): A software package/ system to facilitate the creation.
Instructor: Churee Techawut Basic Concepts of Relational Database Chapter 5 CS (204)321 Database System I.
DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.
Lecture 7 Integrity & Veracity UFCE8K-15-M: Data Management.
Data Integrity An empty database is a correct database.
The Relational Database Model
Chapter 2 The Relational Data Model. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Relational model basics Integrity.
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.
Switch off your Mobiles Phones or Change Profile to Silent Mode.
Relational Database. Database Management System (DBMS)
Slide Chapter 5 The Relational Data Model and Relational Database Constraints.
3 1 Chapter 3 The Relational Database Model Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel.
Module Coordinator Tan Szu Tak School of Information and Communication Technology, Politeknik Brunei Semester
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
3 1 Chapter 3 The Relational Database Model Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Switch off your Mobiles Phones or Change Profile to Silent Mode.
Database Systems: Design, Implementation, and Management Tenth Edition Chapter 3 The Relational Database Model.
CSE314 Database Systems Lecture 3 The Relational Data Model and Relational Database Constraints Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
The relational model A data model (in general) : Integrated collection of concepts for describing data (data requirements). Relational model was introduced.
3 1 Database Systems The Relational Database Model.
3 1 Chapter 3 The Relational Database Model Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 3 The Relational Database Model.
CHAPTER 2 : RELATIONAL DATA MODEL Prepared by : nbs.
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.
Week 2 Lecture The Relational Database Model Samuel ConnSamuel Conn, Faculty Suggestions for using the Lecture Slides.
LECTURE TWO Introduction to Databases: Data models Relational database concepts Introduction to DDL & DML.
Relational Algebra COMP3211 Advanced Databases Nicholas Gibbins
Getting started with Accurately Storing Data
Ritu CHaturvedi Some figures are adapted from T. COnnolly
Relational Algebra Database Management Systems, 3rd ed., Ramakrishnan and Gehrke, Chapter 4.
The Relational Database Model
Database Systems: Design, Implementation, and Management Tenth Edition
Lecture 2 The Relational Model
Theory behind the relational engine
Theory behind the relational engine
Chapter 3 The Relational Database Model
The Relational Database Model
Contents Preface I Introduction Lesson Objectives I-2
DCT 2053 DATABASE CONCEPT Chapter 2.2 CONTINUE
Database Design: Relational Model
INSTRUCTOR: MRS T.G. ZHOU
Database Systems: Design, Implementation, and Management
Presentation transcript:

Switch off your Mobiles Phones or Change Profile to Silent Mode

Relational Model and SQL

Three Parts of Relational Model Structural Part Type of structures (building blocks) from which database is constructed. Manipulative Part Operations which are used for retrieving and updating data in database. Integrity Part Rules that all valid databases must obey.

Relational Database Language Data Definition Language (DDL) Used to define database schema – structural part of relational model Language that allows creation and description of tables (relations) and their relationship within database. Result of compilation of DDL statements is set of relations stored in special files collectively called system catalog (data dictionary)

Relational Database Language Data Manipulation Language (DML) Used to manipulation data in database – manipulative part. Language that provides set of operations (Insert, Modify, Retrieve and Delete) to support basic data manipulation on data.

SQL vs Relational Algebra SQL Deals with both structural part (DDL) and manipulative part (DML) of relational model. Examples of DDL statements CREATE, ALTER, DROP, RENAME Examples of DML statements INSERT, UPDATE, DELETE, SELECT Relational Algebra Deals with manipulative part of relational model. Contains set of 8 operators.

SQL vs Relational Algebra Difference in power / function Difference in styles of expression SQLRelational Algebra Both DDL and DMLDML only SQLRelational Algebra Non procedural languageProcedural language Descriptive (specify what to retrieve) Prescriptive (specify how to retrieve) Problem specificationProblem solving procedure

Relational Algebra Collection of high level operators that operate on relations Traditional set operations Union, Intersection, Difference, Product Special relational operations Restriction, Projection, Join, Division

Definition of Algebra

Syntax of Relational Algebra RESTRICT relationa-name-1 WHERE condition [GIVING result-relational-name] PROJECT relationa-name-1 OVER attribute-list [GIVING result-relational- name] JOIN relationa-name-1 AND relationa- name-2 [OVER join-attribute-list] [GIVING result-relational-name]

Syntax of Relational Algebra DIVIDE dividend-relation-name BY divisor-relation-name [OVER common- attribute-list] [GIVING result-relational- name] relation-name-1 UNION relation-name-2 [GIVING result-relation-name] relation-name-1 PRODUCT relation- name-2 [GIVING result-relation-name] Relation-name-1 DIFFERENCE relation- name-2 [GIVING result-relation-name]

Syntax of Relational Algebra Relation-name-1 INTERSECT relation- name-2 [GIVING result-relation-name]

Example Database

Union UNION of two union-compatible relations A and B, A UNOIN B, is relation with same heading as each of A and B with body consisting of set of all tuples belonging to either A or B or both. UNION combines all rows from two relations, excluding duplicate rows. The relations must have the same attribute characteristics (the columns and domains must be identical) to be used in the UNION.

Union 3 rd Year Students UNION 2 nd Year Students

Intersection INTERSECTION of two union- compatible relations A and B, A INTERSECTION B, is relation with same heading as each of A and B with body consisting of set of all tuples beloging to both A and B. INTERSECTION yields only the rows that appear in both relations. You cannot use INTERSECTION if one of attributes is numeric and one is character-based.

Intersect Operator

Difference DIFFERENCE of two union-compatible relations A and B, A MINUS B (or A DIFFERENCE B), is relation with same heading as each of A and B with body consisting of set of all tuples belonging to A and not to B DIFFERENCE yields all rows in one relation that are not found in the other relation; that is, it subtracts one relation from the other.

Difference

Cartesian Product Cartesian Product of two product compatible relations A and B, A TIMES B or A PRODUCT B, is relation with heading that is coalescing of headings of A and B and with body consisting of set of all tuples t such that t is coalescing of tuple a belonging to A and tuple b belonging to B. Cardinality of results is product of cardinalities of A and B, and degree of result is sum of their degrees.

Cartesian Product

Restrict (Select) RESTRICT operator effectively yields a ‘horizontal’ subset of give relation, which is obtained by selecting all tuples that satisfied restriction condition defined by WHERE clause consisting of arbitrary Boolean combination of simple conditions. RESTRICT, also known as SELECT, yields values for all rows found in a relation that satisfy a given condition.

Restrict (Select)

Project PROJECTION operator yields all values for selected attributes. In other words, PROJECT yields a vertical subset of a relation.

Project PROJECT 3 rd Year Students OVER Student PROJECT Current-marks OVER course

Project PROJECT Current-marks OVER students, course

Divide Division of R by S, R DIVIDEBY S, is relation whose header part is A1, A2, …., An and where each tuple is value for R A such that values of R B occurring with this value for R A in tuples of R correspond to all values of S B in S.

Divide

Natural Join JOIN allows information to be combined from two or more relations. JOIN allows the use of independent relations linked by common attributes. Different types of JOIN: theta join where join condition is any of =, >, =, <= equi join where join condition is = natural join where join condition is = but only one join column is presented in result

Natural Join Natural Join of tables R and S (with union-compatible columns in common) over these columns will result in table with header derived by concatenating headers of R and S and whose tuples are concatenation of all those tuples in R and S where values in common columns to join operator.

Natural Join

Relational Integrity Rules & SQL Relational integrity is one of three parts of Relational Model. Data integrity in Relational Database is concerned with accuracy and validity of data in database. Relational Integrity is enforced via Integrity rules.

Relational Integrity Rules & SQL There are three main types of integrity specified in Relational Model: Domain Integrity Entity Integrity Referential Integrity These integrity rules can be specified and implemented by appropriate SQL statements.

Domain Integrity Range of values that a particular column can take is known as domain. Domain Integrity rule states that: Every attribute is required to satisfy constraint that its values are drawn from relevant domain.

Domain Integrity Example: The domain of gender has only two values (e.g. Male/Female). The domain of start date could be any valid date greater than 01/01/2006. The domain of salary may be restricted to the range 20, ,000. Question: How to implement domain integrity in SQL?

Entity Integrity It is concerned with Primary keys Entity Integrity rules states that: Every base relation must have a primary key and no attribute which forms part of that primary key can accept null values.

Primary Keys PRIMARY KEY for a table T1 is a column PK of T1 such that, at any given time, no two rows of T1 have same value for PK. An entity’s primary key is one or more of its attributes which together uniquely identify an occurrence of the entity.

Primary Keys STUDENT (Student-ID, Student-Name, Address) Student-idStudent-nameAddress S1001Tom12a Clover Street S1002AlexFlat B High Street S1003Brown218 Tulip Road STUDENT

Primary Keys FEATURES Can never take on a particular set of values in more than one occurrence of the entity. No primary key attribute can have a null value. Every attribute in the primary key is mandatory.

Implementation of Entity Integrity In Oracle using CREATE TABLE / ALTER TABLE statement: CREATE TABLE Customer (Customer_NoNumber(10) Primary Key,NameVarchar2(20),AddressVarchar2(20),Depot_NoNumber(10),Credit_LimitNumber(10));

Referential Integrity It is concerned with Foreign keys. Referential Integrity rules states that: Database must not contain any unmatched Foreign key values.

Foreign Key FOREIGN KEY is a column FK of some table T2 such that, at any given time, every (non NULL) value of FK in T2 is required to be equal to the value of the PRIMARY KEY PK in some row of some base table T1.

Foreign Key Lecturer-idLecturer-nameDepartmentSalary W01Emma GregComputing35,000 S01Wendy HolderComputing42,000 D01Amy KingAccounting27,000 J02Bob JonesComputing29,000 N01Bob WhalesAccounting36,500 J01Jack NelsonHistory41,500 LECTURER(Lecture-Id, Lecture-Name, Department, Salary) DepartmentLocation ComputingMoorgate AccountingStaples HistoryLewiston LECTURER-LOCATION(Department*, Location

Foreign Key Cust-idCust-nameCredit-StatusBusiness-type 1001SmithExcellentRetail 1910JonesGoodWholesale 2450BrownFairMultiple CUSTOMER Order-noDateCust-id* 10001/02/ /06/ /06/ ORDER Order-no*Item-noItem-nameQuality 10011Spade Shovel Spade Shovel50 ORDER-LINE

Foreign Key Feature: There is no requirement that a Foreign Key be a component of the Primary Key. Dept-code…… DEPARTMENT Empl-no……Dept-code*…… EMPLOYEE Feature: A foreign key will be composite if the primary key it matches is composite. Manufacturer-nameModel-name…… VEHICLE Vehicle-noManufacturer-name*Model-name*… VEHICLE-IN-STOCK

Foreign Key Feature: Many-To-Many relationships are always decomposed with Foreign keys making up a composite Primary Key. Supp-no…… SUPPLIER Supp-no*Part-no*…… SUPPLY Part-no…… PART

Foreign Key Feature: Note that T1 and T2 do not have to be distinct Empl-no……Mge-no*…… EMPLOYEE

Foreign Key Cust-idCust-nameCredit-StatusBusiness-type 1001SmithExcellentRetail 1910JonesGoodWholesale 2450BrownFairMultiple CUSTOMER Order-noDateCust-id* 10001/02/ /06/ /06/ ORDER Feature: There is no requirement that a given Primary Key value must appear in a corresponding Foreign Key.

Referential Integrity If a 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. CUSTOMER ORDER places

Referential Integrity Cust-idCust-nameCredit-StatusBusiness-type 1001SmithExcellentRetail 1910JonesGoodWholesale 2450BrownFairMultiple CUSTOMER(Cust-id, Cust-name, Credit-status, Business-type Order-noDateCust-id* 10001/02/ /06/ /06/ ORDER(Order-no, Date, Cust-id*)

Referential Integrity It ought to be impossible to delete Cust_id 1001 in Customer table and at same time leave Cust_id 1001 undisturbed in Order table. It ought to be impossible to update Cust_id value in Customer tuple (e.g changed to 200) and at same time leave Order table unchanged. CUSTOMER ORDER places

Referential Integrity ON DELETE and ON UPDATE can have NO ACTION or CASCADE or SET NULL or SET DEFAULT RESTRICTED / NO ACTION Default option Operation is ‘restricted’ to the case where no such matching occurs. Attempt to delete (update) customer id 1001 fails.

Referential Integrity CASCADES Operation cascades to delete matches as well. Delete or Update customer id 1001 and orders 101. NULLIFIES Foreign key is set to null in all matches and record is deleted (updated). Used only when foreign key can accept null values Delete (update) record, set cust_id in orders 101 to null.

Referential Integrity DEFAULT This is alternative to SET NULL Foreign key is in all matches is set to some default value such as ‘9999’ to represent missing information Delete (update) record, set cust_id in orders 101 to ‘9999’.

Referential Integrity Implement Current standard of SQL “SQL/92” has included Referential Integrity Constraints, defined at data definition stage automatically. Subsequently, with each insert, update and delete operation, there is check that referential integrity rule is not iolated.

Referential Integrity Implement CREATE TABLE Customer (Cust_idNumber(4)NOT NULL,Cust_NameVarchar2(20)NOT NULL,Business_TypeVarchar2(20), PRIMARY KEY (Cust_id));

Referential Integrity Implement CREATE TABLE Order (Order_NoNumber(3)NOT NULL,Order_DateDateNOT NULL,Cust_idNumber(4), PRIMARY KEY (Order_No), FOREIGN KEY (Cust_id) REFERENCES Customer (Cust_id) ON DELETE CASCADE ON UPDATE CASCADE); Question: Can you create Order table before Customer table? Why?

Application Specific or User Defined Integrity Rules Main (general) Integrity rules Above three Relational Integrity rules Additional application specific or user defined integrity rules There could be (many) additional integrity rules which only apply to particular application / database.

Application Specific or User Defined Integrity Rules Question: Consider university student database; - what could be additional integrity rules? Answers Possible additional application specific rules could be: no undergraduate student is allowed to take a postgraduate module. no module can be taken unless its pre- requisite module has been taken. no student can be registered for module if maximum capacity has reached.

Any Questions?