Relational terminology. Databases - Sets & Relations. Sets. Membership

Similar documents
This lecture. Basic Syntax

Databases - Relational Algebra. (GF Royle, N Spadaccini ) Databases - Relational Algebra 1 / 24

This lecture. Projection. Relational Algebra. Suppose we have a relation

Databases SQL2. Gordon Royle. School of Mathematics & Statistics University of Western Australia. Gordon Royle (UWA) SQL2 1 / 26

Sets MAT231. Fall Transition to Higher Mathematics. MAT231 (Transition to Higher Math) Sets Fall / 31

Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103. Chapter 2. Sets

2 Review of Set Theory

Relational Database: The Relational Data Model; Operations on Database Relations

This lecture. Databases -Normalization I. Repeating Data. Redundancy. This lecture introduces normal forms, decomposition and normalization.

A set with only one member is called a SINGLETON. A set with no members is called the EMPTY SET or 2 N

SET DEFINITION 1 elements members

Databases -Normalization I. (GF Royle, N Spadaccini ) Databases - Normalization I 1 / 24

CS100: DISCRETE STRUCTURES

The Relational Model

2.1 Sets 2.2 Set Operations

2.2.2.Relational Database concept

Basant Group of Institution

Mahathma Gandhi University

Slides for Faculty Oxford University Press All rights reserved.

Conceptual Data Modeling

The Entity-Relationship Model (ER Model) - Part 2

SQL: Concepts. Todd Bacastow IST 210: Organization of Data 2/17/ IST 210

Set and Set Operations

WHAT IS SQL. Database query language, which can also: Define structure of data Modify data Specify security constraints

SOFTWARE ENGINEERING DESIGN I

CPS221 Lecture: Relational Database Querying and Updating

CS211 Lecture: Database Querying and Updating

CPS221 Lecture: Relational Database Querying and Updating

2.2 Set Operations. Introduction DEFINITION 1. EXAMPLE 1 The union of the sets {1, 3, 5} and {1, 2, 3} is the set {1, 2, 3, 5}; that is, EXAMPLE 2

CS2300: File Structures and Introduction to Database Systems

Relational Databases. Relational Databases. Extended Functional view of Information Manager. e.g. Schema & Example instance of student Relation

LECTURE 8: SETS. Software Engineering Mike Wooldridge

Lecture 4. Lecture 4: The E/R Model

The Relational Model. Week 2

Informatics 1: Data & Analysis

Informatics 1: Data & Analysis

Databases - Classic Models

Database Management System Dr. S. Srinath Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No.

SQL Simple Queries. Chapter 3.1 V3.01. Napier University

1D D0-541 CIW v5 Database Design Specialist Version 1.7

2. Sets. 2.1&2.2: Sets and Subsets. Combining Sets. c Dr Oksana Shatalov, Fall

EE221 Databases Practicals Manual

What is an algebra? A formal system of manipulation of symbols to deal with general statements of relations.

10/11/2018. Partial Orderings. Partial Orderings. Partial Orderings. Partial Orderings. Partial Orderings. Partial Orderings

Math 110 FOUNDATIONS OF THE REAL NUMBER SYSTEM FOR ELEMENTARY AND MIDDLE SCHOOL TEACHERS

Lecture 5. Lecture 5: The E/R Model

The SQL data-definition language (DDL) allows defining :

THE RELATIONAL DATA MODEL CHAPTER 3 (6/E) CHAPTER 5 (5/E)

The Next Step: Designing DB Schema. Chapter 6: Entity-Relationship Model. The E-R Model. Identifying Entities and their Attributes.

CSC Discrete Math I, Spring Sets

Ian Kenny. November 28, 2017

ENTITY-RELATIONSHIP MODEL. CS 564- Spring 2018

CS 1200 Discrete Math Math Preliminaries. A.R. Hurson 323 CS Building, Missouri S&T

2.1 Symbols and Terminology

Chapter 3: Introduction to SQL. Chapter 3: Introduction to SQL

Introduction to Database Systems. The Relational Data Model

Chapter 3: Introduction to SQL

CMPT 354: Database System I. Lecture 2. Relational Model

Introduction to Database Systems. The Relational Data Model. Werner Nutt

This lecture. Databases - SQL II. Counting students. Summary Functions

Relational Algebra for sets Introduction to relational algebra for bags

Information Systems. Relational Databases. Nikolaj Popov

Databases - SQL II. (GF Royle, N Spadaccini ) Structured Query Language II 1 / 22

Complexity Theory. Compiled By : Hari Prasad Pokhrel Page 1 of 20. ioenotes.edu.np

Chapter 3: Introduction to SQL

Databases - Relations in Databases. (N Spadaccini 2010) Relations in Databases 1 / 16

Chapter 6: Entity-Relationship Model. The Next Step: Designing DB Schema. Identifying Entities and their Attributes. The E-R Model.

Chapter 4. The Relational Model

Learn Relational Database from Scratch. Dan Li, Ph.D. Associate Professor Computer Science Eastern Washington University

Database Languages. A DBMS provides two types of languages: Language for accessing & manipulating the data. Language for defining a database schema

Relational Query Languages. Preliminaries. Formal Relational Query Languages. Example Schema, with table contents. Relational Algebra

Relational Query Languages: Relational Algebra. Juliana Freire

Relational Database Model. III. Introduction to the Relational Database Model. Relational Database Model. Relational Terminology.

7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING

Database Systems: Design, Implementation, and Management Tenth Edition. Chapter 4 Entity Relationship (ER) Modeling

Introduction to Sets and Logic (MATH 1190)

Today s Topics. What is a set?

Lecture 3 SQL. Shuigeng Zhou. September 23, 2008 School of Computer Science Fudan University

ACS-3902 Fall Ron McFadyen 3D21 Slides are based on chapter 5 (7 th edition) (chapter 3 in 6 th edition)

Review of Sets. Review. Philippe B. Laval. Current Semester. Kennesaw State University. Philippe B. Laval (KSU) Sets Current Semester 1 / 16

Using Relational Databases for Digital Research

Relational Algebra. Lecture 4A Kathleen Durant Northeastern University

Chapter 3B Objectives. Relational Set Operators. Relational Set Operators. Relational Algebra Operations

Relational Algebra. Mr. Prasad Sawant. MACS College. Mr.Prasad Sawant MACS College Pune

Computer Science Applications to Cultural Heritage. Relational Databases

CS 4604: Introduction to Database Management Systems. B. Aditya Prakash Lecture #5: Entity/Relational Models---Part 1

E-R Model. Hi! Here in this lecture we are going to discuss about the E-R Model.

The Relational Model

Copyright 2016 Ramez Elmasr and Shamkant B. Navathei

Lecture Notes for 3 rd August Lecture topic : Introduction to Relational Model. Rishi Barua Shubham Tripathi

Administrivia. CS 235: Introduction to Databases. Examples. What is a DBMS? The DBMS Marketplace. Relational Model

Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition. Chapter 7 Data Modeling with Entity Relationship Diagrams

The Language of Sets and Functions

Chapter 6 The Relational Algebra and Relational Calculus

Why Study the Relational Model? The Relational Model. Relational Database: Definitions. The SQL Query Language. Relational Query Languages

Introduction Relational Algebra Operations

Relational Algebra Part I. CS 377: Database Systems

Relational Algebra. Note: Slides are posted on the class website, protected by a password written on the board

SQL - Subqueries and. Schema. Chapter 3.4 V4.0. Napier University

Class Information. Textbooks. Grading. Final Project. Grading. CS 440: Database Management Systems. Instructor:

Transcription:

Relational terminology Databases - & Much of the power of relational databases comes from the fact that they can be described analysed mathematically. In particular, queries can be expressed with absolute precision using either The relational algebra A procedural language expressing how to extract information from the database. The relational calculus A declarative language expressing what information should be extracted from the database. (Gf Royle 2006-8, N Spadaccini 2008) & 1 / 27 (Gf Royle 2006-8, N Spadaccini 2008) & 2 / 27 Membership A set is simply a collection of objects, is usually denoted by a capital letter such as A. A set can be specified just by listing all of its members explicitly A = {George, John, James Thomas} B = {red, green, blue} C = {2, 4, 6, 8, 10} or sometimes by specifying a pattern D = {2, 4, 6, 8,...} The symbol is used to denote membership of the set i.e. whether an object belongs to the set or not. Therefore but Similarly but George A violet / B 102 D 999 / D (Gf Royle 2006-8, N Spadaccini 2008) & 3 / 27 (Gf Royle 2006-8, N Spadaccini 2008) & 4 / 27

Defining Properties Cardinality A more precise way of defining the set D is to use a defining property of the set. D = {x x is a positive even integer} This way of defining a set is reminiscent of the WHERE statement of SQL. can be defined in terms of other sets like this E = {x x D x is a square} The cardinality of a set is its size; some sets are finite in that they have a specific number of elements while some are infinite. The sets A, B C are all finite, while D is infinite. There is a very special set that is called the empty set because it contains no elements. Clearly most of the sets that we deal with in databases are finite. This syntax is now almost identical to an SQL statement. (Gf Royle 2006-8, N Spadaccini 2008) & 5 / 27 (Gf Royle 2006-8, N Spadaccini 2008) & 6 / 27 Subsets Supersets Union A set X is a subset of a set Y, denoted X Y if every member of X is also a member of Y. There are two special cases: Y Given two sets X Y, the union of X Y is the set containing all the objects that are members of X or members of Y. In symbols, we have X Y = {x x X or x Y}. Therefore we have Y Y If we want to express the fact that X is a proper subset of Y then we say X Y. A B = {George, John, James Thomas, red, green, blue} C D = D. (Gf Royle 2006-8, N Spadaccini 2008) & 7 / 27 (Gf Royle 2006-8, N Spadaccini 2008) & 8 / 27

Intersection Cartesian Product Given two sets X Y, the intersection of X Y is the set containing all the objects that are members of X members of Y. In symbols, we have X Y = {x x X x Y}. For database purposes, the Cartesian product is one of the most important set operations. Given two sets X Y, the Cartesian product X Y is the set of ordered pairs with components from X Y respectively: Therefore we have A B = C D = C. X Y = {(x, y) x X, y Y} Notice that the elements of X Y are pairs. (Gf Royle 2006-8, N Spadaccini 2008) & 9 / 27 (Gf Royle 2006-8, N Spadaccini 2008) & 10 / 27 Cartesian Product Example I Cartesian Product Extended If then A F contains all of A = {George, John, James Thomas} F = {Washington, Adams, Jefferson, Madison} (George, Washington) (George, Adams) (George, Jefferson) (George, Madison) (John, Washington) (John, Adams) (John, Jefferson) (John, Madison) (James, Washington) (James, Adams) (James, Jefferson) (James, Madison) (Thomas, Washington) (Thomas, Adams) (Thomas, Jefferson) (Thomas, Madison) If X Y are both finite, then X Y has X Y elements. If X, Y Z are three sets then the Cartesian product X Y Z defined by X Y Z = {(x, y, z) x X, y Y, z Z} has ordered triples as its elements. Sometimes we shorten X X to X 2 X X X to X 3 so on. (Gf Royle 2006-8, N Spadaccini 2008) & 11 / 27 (Gf Royle 2006-8, N Spadaccini 2008) & 12 / 27

Extended Cartesian Product Example Cartesian Products in a DB Suppose that X = {0, 1,..., 255} Then X 3 is the set of all triples {(x, y, z) 0 x, y, z 255} This set could represent, for example, the set of all RGB-colours. Consider a variable like first_name which has type VARCHAR(15). This variable can take on a finite number of legal values, the entire collection of legal values is called the domain of the variable suppose we call this D. Then the entire range of possible (first_name, last_name) combinations is the set D D. The collection of (first_name, last_name) combinations that is actually used in the database is therefore just a subset of D D. (Gf Royle 2006-8, N Spadaccini 2008) & 13 / 27 (Gf Royle 2006-8, N Spadaccini 2008) & 14 / 27 Relation Example I Finally, we are in a position to define a (binary) relation: Definition A binary relation between two sets X Y is a subset of X Y. Given a binary relation R X Y we say that x is related to y in the relation if (x, y) R. Consider the following subset of our earlier example product: (George, Washington) (George, Adams) (George, Jefferson) (George, Madison) (John, Washington) (John, Adams) (John, Jefferson) (John, Madison) (James, Washington) (James, Adams) (James, Jefferson) (James, Madison) (Thomas, Washington) (Thomas, Adams) (Thomas, Jefferson) (Thomas, Madison) Under this relation, two names are related if they form the name of one of the first four American presidents. (Gf Royle 2006-8, N Spadaccini 2008) & 15 / 27 (Gf Royle 2006-8, N Spadaccini 2008) & 16 / 27

Relation Example 2 Relation Example 3 Let X be the set of all positive integers, define a relation as follows: R = {(x, y) x is a divisor of y}. Let X be the set of all issued UWA student numbers, let Y be the set of all units at UWA. Then we can define a relation EnrolledIn such that (s, c) EnrolledIn It follows that (2, 4) R (5, 100) R (3, 997) / R if only if the student with student number s is enrolled in the unit with code c. Thus a typical element of this relation might be something like (10423884, CITS3240). (Gf Royle 2006-8, N Spadaccini 2008) & 17 / 27 (Gf Royle 2006-8, N Spadaccini 2008) & 18 / 27 Cardinality A binary relation R X Y is called one-to-one if Each x X appears in exactly one pair (x, y) R Each y Y appears in exactly one pair (x, y) R One-to-many What happens if we alter the relation to include the fifth president, James Adams? Monroe Thomas Adams Thomas Adams James Jefferson James Jefferson John Washington John Washington George Madison George Madison This relation is now called one-to-many because it is possible for one element of x to be related to many elements of y. (Gf Royle 2006-8, N Spadaccini 2008) & 19 / 27 (Gf Royle 2006-8, N Spadaccini 2008) & 20 / 27

Many-to-many Frequently a relation is many-to-many such as the is a divisor of relation discussed earlier.. 10 9 8 7 6 5 4 3 2 1. 10 9 8 7 6 5 4 3 2 1 Entity An entity is an object or event in which we are interested an entity is described using a set of attributes. For example, we might use the attributes student-id name to describe a student. Then each individual student has a particular value for each attribute. An entity set is a collection of similar objects in that every entity in the set has the same attributes not the same values, but the same attributes. For example, the set of all students is an entity set with two attributes. (Gf Royle 2006-8, N Spadaccini 2008) & 21 / 27 (Gf Royle 2006-8, N Spadaccini 2008) & 22 / 27 Diagrammatic Representation Entity An entity set is described by using a specific type of diagram; a rectangle represents the entity set, while ovals represent the attributes. student-id Students name Each attribute of an entity set has a domain, which is the complete range of legal values for that attribute. So if D 1 is the set of all legal student numbers, D 2 the set of all legal names, then a specific entity set can be described just as a particular subset of D 1 D 2. Therefore an entity set with two attributes with domains D 1 D 2 is nothing more than a binary relation between D 1 D 2. (Gf Royle 2006-8, N Spadaccini 2008) & 23 / 27 (Gf Royle 2006-8, N Spadaccini 2008) & 24 / 27

Entity in an RDBMS Arity The whole point of all of this terminology is that in a relational database an entity set with two attributes is represented by a binary relation. Student-id : CHAR(8) Name: VARCHAR(15) 30781233 John Smith 30721438 Emily Tan 30611345 Mark James 30551001 Jennifer Lee The relation schema is the names types of the columns, while the relation instance is the collection of rows. Of course, most entity sets have more than two attributes so cannot be modelled by a binary relation. More generally, if D 1, D 2,..., D n are n sets then a relation with arity n is defined to be a subset R D 1 D 2 D n. A relation with arity 2 is binary, while a relation with arity 3 is called ternary. (Gf Royle 2006-8, N Spadaccini 2008) & 25 / 27 (Gf Royle 2006-8, N Spadaccini 2008) & 26 / 27 Ternary Example Let S be the set of all students, U the set of all units L the set of all lecturers. Then we could define a ternary relation where Teaches L U S (l, u, s) Teaches if l is the lecturer for unit u being taken by student s. The information contained in a ternary relation cannot be represented just by binary relations between S, U L. (Gf Royle 2006-8, N Spadaccini 2008) & 27 / 27