RELATIONAL QUERY LANGUAGES

Size: px
Start display at page:

Download "RELATIONAL QUERY LANGUAGES"

Transcription

1 RELATIONAL QUERY LANGUAGES These comments we make on the relational data model are a short introduction to the types of query languages which can be used against a relational database. Before we start we need to clear up a little notation. A table consists of a collection of user data presented in tabular form. A table has rows, one row for each individual real-world thing the table models as a group and columns, one column for each piece of information about the real-world things modeled by the table. We refer to the table schema as the list of column headers. A table schema is an empty table. as for naming conventions we use a capital letter to start a table name, Cardholder, lower-case letters for column names, b-name, and underlined table names to represent table schemas, Cardholder. For much of these notes we will use Venn Diagrams as a modeling tool for building our queries. We ll see that viewing tables as sets is no handicap in understanding either relational algebra or SQL. In a Venn Diagram we represent a set as a circle. The label beside a circle indicates what elements belong to the set. The area outside a circle is understood to be another set called the compliment which contains all elements not in the set. In both A AND B A B In neither A nor B In A and not B In B and NOT A In theory, query languages divide themselves into two groups - relational algebra-type languages and relational calculus-type languages. In practice, most query languages are a combination of the two. Relational Algebra The identifying feature of a relational algebra-type query language is that it treats a table like a set. Therefore, the operations it uses are operations against sets (tables) whose results are other sets (tables). These operations are: SELECTION PROJECTION CARTESIAN-PRODUCT UNION 1

2 INTERSECT SET-DIFFERENCE JOIN QUOTIENT We will see examples of these operations before looking at a particular query language. SELECTION We can think of SELECTION as taking a (horizontal) subset of the rows of a table. Only those rows where the where condition is satisfied are selected. SELECT <table_name> WHERE <condition> /* this condition is satisfied by each row in the answer */ Find the Cardholders from Modena. SELECT Cardholder WHERE b-address = Modena The answer consists of all rows in the Cardholder table where the b-address column has the value Modena. borrower# b-name b-address b-status 2653 mike Modena senior NOTE: Selection works on one table at a time. If you need data from several tables in your answer you need to combine these tables before you select any rows from the combined tables. PROJECTION Just as SELECTION creates what looks like a horizontal subset of the rows of a table, PROJECTION creates a vertical subset in the sense that certain of the columns are suppressed and duplicate rows in the answer table are also suppressed. PROJECT <table_name> OVER <column_list> /* mention the columns you want to keep */ Find the addresses of all Cardholders. PROJECT Cardholder OVER b-address 2

3 The answer consists of all rows in the Cardholder table where only the b-address column shows. If more than one cardholder lives at the same address we don t show this as two distinct rows in the answer table. b-address New Paltz Rosendale Modena Kingston Tilson NOTE: Just like SELECTION, PROJECTION works on only one table at a time. It automatically eliminates duplicate rows in the answer table. This is usually the last operation performed in a relational-algebra query since it produces just the columns we are after in our answer. CARTESIAN-PRODUCT This operation comes straight from mathematics. The CARTESIAN-PRODUCT of two sets consists of a set of ordered pairs (called tuples, the first element in an ordered pair coming from the first set and the second from the second. Cartesian products can involve sets whose elements are themselves tuples. In this case the elements of the cartesian product are tuples formed by combining the original tuples into one long tuple. <table_name> x <table_name> Cartesian-products are usually uninteresting because they combine everything with everything. Suppose we construct the following tables. NAMES = PROJECT Cardholder OVER b-name and ADDRESSES = PROJECT Cardholder OVER b-address Now suppose we form the cartesian-product of these two small tables. NAMES x ADDRESSES At first glance the resulting table would not seem to be very interesting because it holds every cardholder name matched against every cardholder address. Hence this table, by itself, can t help us determine who lives where. I divide the rows of this table into two groups - information and noise. The information rows are those which correspond to the real-world. The noise rows are those which do not correspond to the real world. The cartesian product consists of just two kinds of rows, information and noise. One of the beauties of relational-algebra (and SQL, for that matter) is that we have operations in both 3

4 languages capable of building the information part of a table if we can identify the noisy part. By the way, the mathematical definition of a relation is that it is a subset of a cartesian product. The name Relational Database comes from the fact that all tables in a well-defined and well-maintained relational database are just the silent subsets of some rather noisy cartesian products. UNION The UNION of two tables works by treating the two tables as sets and trying to combine the two sets of rows into a single table. For rows from different tables to fit into the same table we would need, as an a priori condition, that the two original tables look alike. That is to say, they must have the same schema. Otherwise the union operation can not be applied to the tables. Once we know that two tables have the same schema we can perform the union. The resulting table holds all the rows from either of the tables with no dupicate rows. <table_name_1> UNION <table_name_2> Find the borrower numbers of all cardholders who have borrowed OR reserved a book on December 8. Dec8Reserves = SELECT Reserves WHERE r-date = Dec 8 Dec8Borrows = SELECT Borrows WHERE l-date = Dec 8 Reservers = PROJECT Dec8Reserves OVER borrower# Borrowers = PROJECT Dec8Borrows OVER borrower# Answer = Reservers UNION Borrowers Reservers Borrowers Reservers or Borrowers INTERSECT INTERSECT works under much the same constraints as UNION. We treat the two tables as sets and try to combine elements of the two sets of rows into a single table. For rows from different tables to fit into the same table we would need, as an a priori condition, that the two original tables look alike. That is to say, they must have the same schema. Otherwise the intersection operation can not be applied to the tables. Once we know that two tables have the same 4

5 schema we can perform the intersection. The resulting table holds all the rows found in both of the tables with no dupicate rows. <table_name_1> INTERSECT <table_name_2> Find the borrower numbers of all cardholders who have borrowed AND reserved a book on December 8. Dec8Reserves = SELECT Reserves WHERE r-date = Dec 8 Dec8Borrows = SELECT Borrows WHERE l-date = Dec 8 Reservers = PROJECT Dec8Reserves OVER borrower# Borrowers = PROJECT Dec8Borrows OVER borrower# Answer = Reservers INTERSECT Borrowers Reservers Borrowers Reservers and Borrowers SET-DIFFERENCE SET-DIFFERENCE works under much the same constraints as UNION and INTERSECT. We treat the two tables as sets and try to select rows from one table and not the other into a single table. For rows from different tables to be at all comparable we would need, as an a priori condition, that the two original tables look alike. That is to say, they must have the same schema. Otherwise the set difference operation should not be applied to the tables. Once we know that two tables have the same schema we can perform the operation. The resulting table holds all the rows found in just one of the tables. <table_name_1> MINUS <table_name_2> Find the borrower numbers of all cardholders who have reserved BUT NOT borrowed a book on December 8. Dec8Reserves = SELECT Reserves WHERE r-date = Dec 8 Dec8Borrows = SELECT Borrows WHERE l-date = Dec 8 Reservers = PROJECT Dec8Reserves OVER borrower# Borrowers = PROJECT Dec8Borrows OVER borrower# 5

6 Answer = Reservers MINUS Borrowers Reservers Borrowers Reservers but not Borrowers JOIN JOIN is the first relational algebra operation which is substantially new to people familiar with set theory. The idea behind join is to combine tables using their common columns as the joining factor. Since these common columns are usually primary and secondary keys this operation is quite natural. Join is really a combination of three other relational algebra operations - CARTESIAN PRODUCT, SELECT and PROJECT. First you CARTESIAN PRODUCT the two tables concerned. Next you choose the rows in the CARTESIAN PROD- UCT which have the common columns having the same values. Finally you PROJECT out one of the common columns since the row values are identical. JOIN (<table_name_1>, <table_name_2>) [OVER <column_name_list>] or JOIN (<table_name_1>, <table_name_2>) WHERE table_name_1.column_name # table_name_2.column_name NOTE: # means any one of the operators =, <, >,!=, *= or =*. Find the cardholders who have borrowed a book on December 8. Temp = JOIN (Cardholder, Borrows) Answer = SELECT Temp WHERE l-date = Dec 8 This query gives a flavour of relational algebra. Unlike SQL where all operations are bunched into a single command, in relational algebra you do things one step at a time - procedurally!! Join itself is really the composite of three simpler operations. Temp = JOIN (Cardholder, Borrows) can be written Temp1 = Cardholder x Borrows Temp2 = SELECT Temp1 WHERE Cardholder.borrower# = Borrows.borrower# Answer = PROJECT Temp2 OVER Cardholder.borrower#, b-name, b-address, b-status, accession#, l-date 6

7 In other words, a JOIN is just a CARTESIAN PRODUCT followed by a SE- LECT and finished off with a PROJECT. EXERCISE: Show that if R S = then JOIN(R,S) = R S. EXERCISE: Show that if R = S then JOIN(R,S) = R * S. QUOTIENT As a query, QUOTIENT is probably the most counter intuitive. However it comes from a very simple concept in integer arithmetic. Suppose n is an integer and d is another integer we wish to divide into n. Asking the question How many times does d divide into n? is just another way of asking What is the quotient q = n/d? An appropriate definition of integer quotient is the following: DEFINITION 1: The quotient of n by d is the largest integer q such that q d n. Now switch our thoughts to tables. Suppose we have two tables, N and D. Suppose further that we define the following: DEFINITION 2: Let N and D be tables. The quotient table of N by D (written N/D) is the largest table Q such that Q D N. To make sense out of this definition we need to know what it means to multiple two tables and what it means for one table to be less than or equal to another table. If we view tables as sets of rows then the natural cognate of less than or equal to is subset of. The only product we ve seen with respect to tables is the cartesian product. Hence we could rewrite Definition 2 as DEFINITION 2 : Let N and D be tables. The quotient table of N by D (written N/D) is the largest table Q such that Q D N where means cartesian product. Just as with INTERSECT and UNION there are consequences of this definition regarding schemas. Since Q D N as sets, they must, as tables, have the same schemas. Hence Q D = N. In other words, the columns in N consist of precisely the columns in D together with the columns in the Q. Moreover, since a row in the cartesian product, Q D, involves combining all the entries of Q and D there can t be any duplicate columns in Q and D. Hence Q D =. Next, by saying that Q is the largest table such that Q D N we are saying two things: 1. any row of Q concatenated with every row of D is a row in the original table N and, 2. since Q is the largest table with this property no rows that are not in Q satisfy this property. An example is the best way to see QUOTIENT. Find all those cardholders (name and address) who have reserved 7

8 every book published by Prentice-Hall (PH). PHBooks = SELECT Book WHERE pub-name = PH PHISBN = PROJECT PHBooks OVER ISBN /* identifiers of all PH books */ AllReservations = PROJECT Reserves OVER borrower#, ISBN /* all reservations; no dates */ Ans1 = AllReservations / PHISBN Ans2 = JOIN (Ans1, Cardholder) Answer = PROJECT Ans2 OVER b-name, b-address How does QUOTIENT find all cardholders who have reserved all PH books? The key to understanding QUOTIENT is to see what allows a value to belong to the quotient table. First, since AllReservations = {borrower#, ISBN} and PHISBN = {ISBN} it is clear that if Ans1 P HISBN AllReservations that Ans1 = {borrower#}. So at least Ans1 holds the right kind of values. Secondly, for a borrower# to belong to Ans1, it must already belong to AllReservations combined with every PH book. In other words, the corresponding cardholder must have already reserved every PH book. Since Ans1 is the largest table whose CARTESIAN PRODUCT with PHISBN lies inside AllReservations, Ans1 must contain the borrower# of every cardholder who has reserved every PH book. This example should tell us something about QUOTIENT and any query which contains the word all in the condition. Neither of these is trivial and they go together. In general, query complexity can be measured by the presence of words such as all, only, not, none and combinations of these words. Notation Name Symbol Meaning Table R, S, T a collection of rows headed by column headers Table Schema R a list of column names of a table Column A, B, C the name atthe top of a table column Row r, s,t an entry in a table Set of Columns X, Y, Z a subset of a Table Schema Domain Dom(A) the set of possible values of a column Column Value r[a] the value in row r and column A Column List Value r[x] the values in row r for the columns in X Def n: A key to a table is a subset, X, of its schema such that any two rows which agree on X are identical. In symbols this is stated: X is a key if r[x] = s[x] implies r = s where r and s are rows of the table in question.. Def n: A superkey to a table is any subset, X, of the table schema which contains a key. In symbols: if X is a key to R and X Y R then Y is a 8

9 superkey of R. Def n: A candidate key is a key which does not contain a proper subset which is also a key. In symbols: X is a candidate key of a table R if X R, X is a key of R and there does not exist Y X such that Y is a key of R. Def n: A primary key of a table is any chosen candidate key. 9

10 The Library Database Cardholder borrower# b-name b-address b-status 1234 john New Paltz senior 1345 albert Rosendale senior 1325 jo-ann New Paltz junior 2653 mike Modena senior 7635 john Kingston junior 9823 diana Tilson senior 5342 susan Walkill senior Book ISBN title author pub-date c-price pub-name 1-23 DB Ullman CSP 2-34 Netw T baum PH 3-56 Queue K rock Wiley 4-76 SysD J son PH 1-52 DB Date AW 6-99 MMM Br kes AW 7-45 Arch Baer CSP Status b-status loan-limit junior 2 senior 4 Reserves ISBN borrower# r-date Dec Dec Dec Dec Dec Dec Dec Dec 10 10

11 Copy accession# p-price ISBN qt-76.4c qt-78.2c qt-78.2c qs-77.3c qs-77.3c qs-77.3c qs-77.3c qs-77.3c qs-77.3c qp-91.2c qt-76.5c qt-76.5c qt-76.5c qt-75.5c qt-75.3c qt-75.3c Borrows accession# borrower# l-date qt-76.4c Dec 1 qs-77.3c Dec 14 qt-76.5c Nov 30 qt-75.5c Dec 8 qt-78.2c Dec 4 qt-75.3c Dec 4 qt-76.5c Dec 9 qt-76.5c Dec 12 qt-75.3c Dec 1 qt-78.2c Nov 28 11

2.3 Algorithms Using Map-Reduce

2.3 Algorithms Using Map-Reduce 28 CHAPTER 2. MAP-REDUCE AND THE NEW SOFTWARE STACK one becomes available. The Master must also inform each Reduce task that the location of its input from that Map task has changed. Dealing with a failure

More information

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

Relational Database: The Relational Data Model; Operations on Database Relations Relational Database: The Relational Data Model; Operations on Database Relations Greg Plaxton Theory in Programming Practice, Spring 2005 Department of Computer Science University of Texas at Austin Overview

More information

Concepts of Database Management Eighth Edition. Chapter 2 The Relational Model 1: Introduction, QBE, and Relational Algebra

Concepts of Database Management Eighth Edition. Chapter 2 The Relational Model 1: Introduction, QBE, and Relational Algebra Concepts of Database Management Eighth Edition Chapter 2 The Relational Model 1: Introduction, QBE, and Relational Algebra Relational Databases A relational database is a collection of tables Each entity

More information

Relational Model and Relational Algebra A Short Review Class Notes - CS582-01

Relational Model and Relational Algebra A Short Review Class Notes - CS582-01 Relational Model and Relational Algebra A Short Review Class Notes - CS582-01 Tran Cao Son January 12, 2002 0.1 Basics The following definitions are from the book [1] Relational Model. Relations are tables

More information

Database Systems. Basics of the Relational Data Model

Database Systems. Basics of the Relational Data Model Database Systems Relational Design Theory Jens Otten University of Oslo Jens Otten (UiO) Database Systems Relational Design Theory INF3100 Spring 18 1 / 30 Basics of the Relational Data Model title year

More information

Relational model continued. Understanding how to use the relational model. Summary of board example: with Copies as weak entity

Relational model continued. Understanding how to use the relational model. Summary of board example: with Copies as weak entity COS 597A: Principles of Database and Information Systems Relational model continued Understanding how to use the relational model 1 with as weak entity folded into folded into branches: (br_, librarian,

More information

Relational Model, Relational Algebra, and SQL

Relational Model, Relational Algebra, and SQL Relational Model, Relational Algebra, and SQL August 29, 2007 1 Relational Model Data model. constraints. Set of conceptual tools for describing of data, data semantics, data relationships, and data integrity

More information

CS 377 Database Systems

CS 377 Database Systems CS 377 Database Systems Relational Algebra and Calculus Li Xiong Department of Mathematics and Computer Science Emory University 1 ER Diagram of Company Database 2 3 4 5 Relational Algebra and Relational

More information

Today s Topics. What is a set?

Today s Topics. What is a set? Today s Topics Introduction to set theory What is a set? Set notation Basic set operations What is a set? Definition: A set is an unordered collection of objects Examples: Sets can contain items of mixed

More information

Chapter 6 The Relational Algebra and Relational Calculus

Chapter 6 The Relational Algebra and Relational Calculus Chapter 6 The Relational Algebra and Relational Calculus Fundamentals of Database Systems, 6/e The Relational Algebra and Relational Calculus Dr. Salha M. Alzahrani 1 Fundamentals of Databases Topics so

More information

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

Review of Sets. Review. Philippe B. Laval. Current Semester. Kennesaw State University. Philippe B. Laval (KSU) Sets Current Semester 1 / 16 Review of Sets Review Philippe B. Laval Kennesaw State University Current Semester Philippe B. Laval (KSU) Sets Current Semester 1 / 16 Outline 1 Introduction 2 Definitions, Notations and Examples 3 Special

More information

CS121 MIDTERM REVIEW. CS121: Relational Databases Fall 2017 Lecture 13

CS121 MIDTERM REVIEW. CS121: Relational Databases Fall 2017 Lecture 13 CS121 MIDTERM REVIEW CS121: Relational Databases Fall 2017 Lecture 13 2 Before We Start Midterm Overview 3 6 hours, multiple sittings Open book, open notes, open lecture slides No collaboration Possible

More information

Other Relational Query Languages

Other Relational Query Languages APPENDIXC Other Relational Query Languages In Chapter 6 we presented the relational algebra, which forms the basis of the widely used SQL query language. SQL was covered in great detail in Chapters 3 and

More information

Announcements. Relational Model & Algebra. Example. Relational data model. Example. Schema versus instance. Lecture notes

Announcements. Relational Model & Algebra. Example. Relational data model. Example. Schema versus instance. Lecture notes Announcements Relational Model & Algebra CPS 216 Advanced Database Systems Lecture notes Notes version (incomplete) available in the morning on the day of lecture Slides version (complete) available after

More information

Chapter 2: Relational Model

Chapter 2: Relational Model Chapter 2: Relational Model Database System Concepts, 5 th Ed. See www.db-book.com for conditions on re-use Chapter 2: Relational Model Structure of Relational Databases Fundamental Relational-Algebra-Operations

More information

CS 377 Database Systems

CS 377 Database Systems CS 377 Database Systems Relational Data Model Li Xiong Department of Mathematics and Computer Science Emory University 1 Outline Relational Model Concepts Relational Model Constraints Relational Database

More information

Databases-1 Lecture-01. Introduction, Relational Algebra

Databases-1 Lecture-01. Introduction, Relational Algebra Databases-1 Lecture-01 Introduction, Relational Algebra Information, 2018 Spring About me: Hajas Csilla, Mathematician, PhD, Senior lecturer, Dept. of Information Systems, Eötvös Loránd University of Budapest

More information

Databases. Jörg Endrullis. VU University Amsterdam

Databases. Jörg Endrullis. VU University Amsterdam Databases Jörg Endrullis VU University Amsterdam The Relational Model Overview 1. Relational Model Concepts: Schema, State 2. Null Values 3. Constraints: General Remarks 4. Key Constraints 5. Foreign Key

More information

Running Example Tables name location

Running Example Tables name location Running Example Pubs-Drinkers-DB: The data structures of the relational model Attributes and domains Relation schemas and database schemas databases Pubs (name, location) Drinkers (name, location) Sells

More information

SETS. Sets are of two sorts: finite infinite A system of sets is a set, whose elements are again sets.

SETS. Sets are of two sorts: finite infinite A system of sets is a set, whose elements are again sets. SETS A set is a file of objects which have at least one property in common. The objects of the set are called elements. Sets are notated with capital letters K, Z, N, etc., the elements are a, b, c, d,

More information

6. Relational Algebra (Part II)

6. Relational Algebra (Part II) 6. Relational Algebra (Part II) 6.1. Introduction In the previous chapter, we introduced relational algebra as a fundamental model of relational database manipulation. In particular, we defined and discussed

More information

MITOCW watch?v=kz7jjltq9r4

MITOCW watch?v=kz7jjltq9r4 MITOCW watch?v=kz7jjltq9r4 PROFESSOR: We're going to look at the most fundamental of all mathematical data types, namely sets, and let's begin with the definitions. So informally, a set is a collection

More information

CPS 510 Data Base I. There are 3 forms of database descriptions the ANSI/SPARK, 1975 and so on

CPS 510 Data Base I. There are 3 forms of database descriptions the ANSI/SPARK, 1975 and so on Introduction DBMS 1957 A database can be defined as a set of Master files, organized & administered in a flexible way, so that the files in the database can be easily adapted to new unforeseen tasks! Relation

More information

Relational Model & Algebra. Announcements (Tue. Sep. 3) Relational data model. CompSci 316 Introduction to Database Systems

Relational Model & Algebra. Announcements (Tue. Sep. 3) Relational data model. CompSci 316 Introduction to Database Systems Relational Model & Algebra CompSci 316 Introduction to Database Systems Announcements (Tue. Sep. 3) Homework #1 has been posted Sign up for Gradiance now! Windows Azure passcode will be emailed soon sign

More information

Database Design Theory and Normalization. CS 377: Database Systems

Database Design Theory and Normalization. CS 377: Database Systems Database Design Theory and Normalization CS 377: Database Systems Recap: What Has Been Covered Lectures 1-2: Database Overview & Concepts Lecture 4: Representational Model (Relational Model) & Mapping

More information

Relational Algebra and Calculus

Relational Algebra and Calculus and Calculus Marek Rychly mrychly@strathmore.edu Strathmore University, @ilabafrica & Brno University of Technology, Faculty of Information Technology Advanced Databases and Enterprise Systems 7 September

More information

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

Chapter 3B Objectives. Relational Set Operators. Relational Set Operators. Relational Algebra Operations Chapter 3B Objectives Relational Set Operators Learn About relational database operators SELECT & DIFFERENCE PROJECT & JOIN UNION PRODUCT INTERSECT DIVIDE The Database Meta Objects the data dictionary

More information

3.1 Constructions with sets

3.1 Constructions with sets 3 Interlude on sets Sets and functions are ubiquitous in mathematics. You might have the impression that they are most strongly connected with the pure end of the subject, but this is an illusion: think

More information

Ch.6 DB design. Why design? Pitfalls at the two extremes: Redundancy Incompleteness. Two strategies: Bottom-up Top-down. Ch.6 is devoted to bottom-up

Ch.6 DB design. Why design? Pitfalls at the two extremes: Redundancy Incompleteness. Two strategies: Bottom-up Top-down. Ch.6 is devoted to bottom-up Week 7, Lect.3 SKIP CH.5 Other relational languages procedural o Tuple relational calculus o Domain relational calculus non-procedural o QBE (Query By Example) o Datalog Ch.6 DB design Why design? In order

More information

Relational Model & Algebra. Announcements (Thu. Aug. 27) Relational data model. CPS 116 Introduction to Database Systems

Relational Model & Algebra. Announcements (Thu. Aug. 27) Relational data model. CPS 116 Introduction to Database Systems Relational Model & Algebra CPS 116 Introduction to Database Systems Announcements (Thu. Aug. 27) 2 Homework #1 will be assigned next Tuesday Office hours: see also course website Jun: LSRC D327 Tue. 1.5

More information

UNIT- II (Relational Data Model & Introduction to SQL)

UNIT- II (Relational Data Model & Introduction to SQL) Database Management System 1 (NCS-502) UNIT- II (Relational Data Model & Introduction to SQL) 2.1 INTRODUCTION: 2.1.1 Database Concept: 2.1.2 Database Schema 2.2 INTEGRITY CONSTRAINTS: 2.2.1 Domain Integrity:

More information

Chapter 3: Relational Model

Chapter 3: Relational Model Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational Calculus Domain Relational Calculus Extended Relational-Algebra-Operations Modification of the Database

More information

Basant Group of Institution

Basant Group of Institution Basant Group of Institution Visual Basic 6.0 Objective Question Q.1 In the relational modes, cardinality is termed as: (A) Number of tuples. (B) Number of attributes. (C) Number of tables. (D) Number of

More information

Mahathma Gandhi University

Mahathma Gandhi University Mahathma Gandhi University BSc Computer science III Semester BCS 303 OBJECTIVE TYPE QUESTIONS Choose the correct or best alternative in the following: Q.1 In the relational modes, cardinality is termed

More information

Relational Algebra and SQL

Relational Algebra and SQL Relational Algebra and SQL Relational Algebra. This algebra is an important form of query language for the relational model. The operators of the relational algebra: divided into the following classes:

More information

Relational Model Concepts

Relational Model Concepts Relational Model Relational Model Concepts The relational model of data is based on the concept of a Relation. A relation is a mathematical concept based on the idea of sets. Relational Model The model

More information

Chapter 2: Intro to Relational Model

Chapter 2: Intro to Relational Model Chapter 2: Intro to Relational Model Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Example of a Relation attributes (or columns) tuples (or rows) 2.2 Attribute Types The

More information

Relational Model History. COSC 304 Introduction to Database Systems. Relational Model and Algebra. Relational Model Definitions.

Relational Model History. COSC 304 Introduction to Database Systems. Relational Model and Algebra. Relational Model Definitions. COSC 304 Introduction to Database Systems Relational Model and Algebra Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Relational Model History The relational model was

More information

CIS 45, The Introduction. What is a database? What is data? What is information?

CIS 45, The Introduction. What is a database? What is data? What is information? CIS 45, The Introduction I have traveled the length and breadth of this country and talked with the best people, and I can assure you that data processing is a fad that won t last out the year. The editor

More information

CS2300: File Structures and Introduction to Database Systems

CS2300: File Structures and Introduction to Database Systems CS2300: File Structures and Introduction to Database Systems Lecture 9: Relational Model & Relational Algebra Doug McGeehan 1 Brief Review Relational model concepts Informal Terms Formal Terms Table Relation

More information

Chapter 6 The Relational Algebra and Calculus

Chapter 6 The Relational Algebra and Calculus Chapter 6 The Relational Algebra and Calculus 1 Chapter Outline Example Database Application (COMPANY) Relational Algebra Unary Relational Operations Relational Algebra Operations From Set Theory Binary

More information

The Basic (Flat) Relational Model. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

The Basic (Flat) Relational Model. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley The Basic (Flat) Relational Model Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 Outline The Relational Data Model and Relational Database Constraints Relational

More information

THE RELATIONAL DATABASE MODEL

THE RELATIONAL DATABASE MODEL THE RELATIONAL DATABASE MODEL Introduction to relational DB Basic Objects of relational model Properties of relation Representation of ER model to relation Keys Relational Integrity Rules Functional Dependencies

More information

A l Ain University Of Science and Technology

A l Ain University Of Science and Technology A l Ain University Of Science and Technology 6 Handout(6) Database Management Principles and Applications Relational algebra http://alainauh.webs.com/ 1 Handout Outines 6 Basic operations in relational

More information

The Relational Model. csc343, Introduction to Databases Diane Horton Fall 2014

The Relational Model. csc343, Introduction to Databases Diane Horton Fall 2014 The Relational Model csc343, Introduction to Databases Diane Horton Fall 2014 Recap The relational model is based on the concept of a relation or table. Two example relations: Teams Name Home Field Coach

More information

Relational Algebra BASIC OPERATIONS DATABASE SYSTEMS AND CONCEPTS, CSCI 3030U, UOIT, COURSE INSTRUCTOR: JAREK SZLICHTA

Relational Algebra BASIC OPERATIONS DATABASE SYSTEMS AND CONCEPTS, CSCI 3030U, UOIT, COURSE INSTRUCTOR: JAREK SZLICHTA Relational Algebra BASIC OPERATIONS 1 What is an Algebra Mathematical system consisting of: Operands -- values from which new values can be constructed. Operators -- symbols denoting procedures that construct

More information

Relational Algebra and SQL. Basic Operations Algebra of Bags

Relational Algebra and SQL. Basic Operations Algebra of Bags Relational Algebra and SQL Basic Operations Algebra of Bags 1 What is an Algebra Mathematical system consisting of: Operands --- variables or values from which new values can be constructed. Operators

More information

CS 317/387. A Relation is a Table. Schemas. Towards SQL - Relational Algebra. name manf Winterbrew Pete s Bud Lite Anheuser-Busch Beers

CS 317/387. A Relation is a Table. Schemas. Towards SQL - Relational Algebra. name manf Winterbrew Pete s Bud Lite Anheuser-Busch Beers CS 317/387 Towards SQL - Relational Algebra A Relation is a Table Attributes (column headers) Tuples (rows) name manf Winterbrew Pete s Bud Lite Anheuser-Busch Beers Schemas Relation schema = relation

More information

Properties and Definitions

Properties and Definitions Section 0.1 Contents: Operations Defined Multiplication as an Abbreviation Visualizing Multiplication Commutative Properties Parentheses Associative Properties Identities Zero Product Answers to Exercises

More information

The data structures of the relational model Attributes and domains Relation schemas and database schemas

The data structures of the relational model Attributes and domains Relation schemas and database schemas The data structures of the relational model Attributes and domains Relation schemas and database schemas databases First normal form (1NF) Running Example Pubs-Drinkers-DB: Pubs (name, location) Drinkers

More information

Applied Databases. Sebastian Maneth. Lecture 5 ER Model, normal forms. University of Edinburgh - January 25 th, 2016

Applied Databases. Sebastian Maneth. Lecture 5 ER Model, normal forms. University of Edinburgh - January 25 th, 2016 Applied Databases Lecture 5 ER Model, normal forms Sebastian Maneth University of Edinburgh - January 25 th, 2016 Outline 2 1. Entity Relationship Model 2. Normal Forms Keys and Superkeys 3 Superkey =

More information

2.2.2.Relational Database concept

2.2.2.Relational Database concept Foreign key:- is a field (or collection of fields) in one table that uniquely identifies a row of another table. In simpler words, the foreign key is defined in a second table, but it refers to the primary

More information

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

Math 110 FOUNDATIONS OF THE REAL NUMBER SYSTEM FOR ELEMENTARY AND MIDDLE SCHOOL TEACHERS 2-1Numeration Systems Hindu-Arabic Numeration System Tally Numeration System Egyptian Numeration System Babylonian Numeration System Mayan Numeration System Roman Numeration System Other Number Base Systems

More information

Combining schemas. Problems: redundancy, hard to update, possible NULLs

Combining schemas. Problems: redundancy, hard to update, possible NULLs Handout Combining schemas Problems: redundancy, hard to update, possible NULLs Problems? Conclusion: Whether the join attribute is PK or not makes a great difference when combining schemas! Splitting schemas,

More information

Chapter 5. The Relational Data Model and Relational Database Constraints. Slide 5-١. Copyright 2007 Ramez Elmasri and Shamkant B.

Chapter 5. The Relational Data Model and Relational Database Constraints. Slide 5-١. Copyright 2007 Ramez Elmasri and Shamkant B. Slide 5-١ Chapter 5 The Relational Data Model and Relational Database Constraints Chapter Outline Relational Model Concepts Relational Model Constraints and Relational Database Schemas Update Operations

More information

Copyright 2007 Ramez Elmasri and Shamkant B. Navathe. Slide 5-1

Copyright 2007 Ramez Elmasri and Shamkant B. Navathe. Slide 5-1 Slide 5-1 Chapter 5 The Relational Data Model and Relational Database Constraints Chapter Outline Relational Model Concepts Relational Model Constraints and Relational Database Schemas Update Operations

More information

CMP-3440 Database Systems

CMP-3440 Database Systems CMP-3440 Database Systems Relational DB Languages Relational Algebra, Calculus, SQL Lecture 05 zain 1 Introduction Relational algebra & relational calculus are formal languages associated with the relational

More information

Sets. {1, 2, 3, Calvin}.

Sets. {1, 2, 3, Calvin}. ets 2-24-2007 Roughly speaking, a set is a collection of objects. he objects are called the members or the elements of the set. et theory is the basis for mathematics, and there are a number of axiom systems

More information

Database System Concepts, 5 th Ed.! Silberschatz, Korth and Sudarshan See for conditions on re-use "

Database System Concepts, 5 th Ed.! Silberschatz, Korth and Sudarshan See   for conditions on re-use Database System Concepts, 5 th Ed.! Silberschatz, Korth and Sudarshan See www.db-book.com for conditions on re-use " Structure of Relational Databases! Fundamental Relational-Algebra-Operations! Additional

More information

Web Science & Technologies University of Koblenz Landau, Germany. Relational Data Model

Web Science & Technologies University of Koblenz Landau, Germany. Relational Data Model Web Science & Technologies University of Koblenz Landau, Germany Relational Data Model Overview Relational data model; Tuples and relations; Schemas and instances; Named vs. unnamed perspective; Relational

More information

Algebra of Sets (Mathematics & Logic A)

Algebra of Sets (Mathematics & Logic A) Algebra of Sets (Mathematics & Logic A) RWK/MRQ October 28, 2002 Note. These notes are adapted (with thanks) from notes given last year by my colleague Dr Martyn Quick. Please feel free to ask me (not

More information

Database Management Systems. Chapter 4. Relational Algebra. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1

Database Management Systems. Chapter 4. Relational Algebra. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Database Management Systems Chapter 4 Relational Algebra Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Formal Relational Query Languages Two mathematical Query Languages form the basis

More information

Chapter 6 Part I The Relational Algebra and Calculus

Chapter 6 Part I The Relational Algebra and Calculus Chapter 6 Part I The Relational Algebra and Calculus Copyright 2004 Ramez Elmasri and Shamkant Navathe Database State for COMPANY All examples discussed below refer to the COMPANY database shown here.

More information

Chapter 3. Set Theory. 3.1 What is a Set?

Chapter 3. Set Theory. 3.1 What is a Set? Chapter 3 Set Theory 3.1 What is a Set? A set is a well-defined collection of objects called elements or members of the set. Here, well-defined means accurately and unambiguously stated or described. Any

More information

Informatics 1: Data & Analysis

Informatics 1: Data & Analysis Informatics 1: Data & Analysis Lecture 3: The Relational Model Ian Stark School of Informatics The University of Edinburgh Tuesday 24 January 2017 Semester 2 Week 2 https://blog.inf.ed.ac.uk/da17 Lecture

More information

Relational Model and Relational Algebra

Relational Model and Relational Algebra UNIT-III Relational Model and Relational Algebra 1) Define the following terms with an example for each. 8 Marks (Jun / July2014) Super key: A set of attributes SK of R such that no two tuples in any valid

More information

Chapter 3. The Relational Model. Database Systems p. 61/569

Chapter 3. The Relational Model. Database Systems p. 61/569 Chapter 3 The Relational Model Database Systems p. 61/569 Introduction The relational model was developed by E.F. Codd in the 1970s (he received the Turing award for it) One of the most widely-used data

More information

2.1 Sets 2.2 Set Operations

2.1 Sets 2.2 Set Operations CSC2510 Theoretical Foundations of Computer Science 2.1 Sets 2.2 Set Operations Introduction to Set Theory A set is a structure, representing an unordered collection (group, plurality) of zero or more

More information

The Relational Data Model and Relational Database Constraints

The Relational Data Model and Relational Database Constraints CHAPTER 5 The Relational Data Model and Relational Database Constraints Copyright 2017 Ramez Elmasri and Shamkant B. Navathe Slide 1-2 Chapter Outline Relational Model Concepts Relational Model Constraints

More information

ITCS 3160 DATA BASE DESIGN AND IMPLEMENTATION

ITCS 3160 DATA BASE DESIGN AND IMPLEMENTATION ITCS 3160 DATA BASE DESIGN AND IMPLEMENTATION JING YANG 2010 FALL Class 3: The Relational Data Model and Relational Database Constraints Outline 2 The Relational Data Model and Relational Database Constraints

More information

SIT772 Database and Information Retrieval WEEK 6. RELATIONAL ALGEBRAS. The foundation of good database design

SIT772 Database and Information Retrieval WEEK 6. RELATIONAL ALGEBRAS. The foundation of good database design SIT772 Database and Information Retrieval WEEK 6. RELATIONAL ALGEBRAS The foundation of good database design Outline 1. Relational Algebra 2. Join 3. Updating/ Copy Table or Parts of Rows 4. Views (Virtual

More information

Relational Model and Relational Algebra. Rose-Hulman Institute of Technology Curt Clifton

Relational Model and Relational Algebra. Rose-Hulman Institute of Technology Curt Clifton Relational Model and Relational Algebra Rose-Hulman Institute of Technology Curt Clifton Administrative Notes Grading Weights Schedule Updated Review ER Design Techniques Avoid redundancy and don t duplicate

More information

Discrete Mathematics

Discrete Mathematics Discrete Mathematics Lecture 2: Basic Structures: Set Theory MING GAO DaSE@ ECNU (for course related communications) mgao@dase.ecnu.edu.cn Sep. 18, 2017 Outline 1 Set Concepts 2 Set Operations 3 Application

More information

DC62 Database management system JUNE 2013

DC62 Database management system JUNE 2013 Q2 (a) Explain the differences between conceptual & external schema. Ans2 a. Page Number 24 of textbook. Q2 (b) Describe the four components of a database system. A database system is composed of four

More information

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

What is an algebra? A formal system of manipulation of symbols to deal with general statements of relations. Lecture 4. Relational Algebra By now, we know that (a) All data in a relational DB is stored in tables (b) there are several tables in each DB (because of Normalization), and (c) often the information

More information

Relational Model History. COSC 416 NoSQL Databases. Relational Model (Review) Relation Example. Relational Model Definitions. Relational Integrity

Relational Model History. COSC 416 NoSQL Databases. Relational Model (Review) Relation Example. Relational Model Definitions. Relational Integrity COSC 416 NoSQL Databases Relational Model (Review) Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Relational Model History The relational model was proposed by E. F. Codd

More information

RELATIONAL ALGEBRA II. CS121: Relational Databases Fall 2017 Lecture 3

RELATIONAL ALGEBRA II. CS121: Relational Databases Fall 2017 Lecture 3 RELATIONAL ALGEBRA II CS121: Relational Databases Fall 2017 Lecture 3 Last Lecture 2 Query languages provide support for retrieving information from a database Introduced the relational algebra A procedural

More information

RDBMS- Day 4. Grouped results Relational algebra Joins Sub queries. In today s session we will discuss about the concept of sub queries.

RDBMS- Day 4. Grouped results Relational algebra Joins Sub queries. In today s session we will discuss about the concept of sub queries. RDBMS- Day 4 Grouped results Relational algebra Joins Sub queries In today s session we will discuss about the concept of sub queries. Grouped results SQL - Using GROUP BY Related rows can be grouped together

More information

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

Relational terminology. Databases - Sets & Relations. Sets. Membership 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

More information

Ian Kenny. November 28, 2017

Ian Kenny. November 28, 2017 Ian Kenny November 28, 2017 Introductory Databases Relational Algebra Introduction In this lecture we will cover Relational Algebra. Relational Algebra is the foundation upon which SQL is built and is

More information

Today s topics. Null Values. Nulls and Views in SQL. Standard Boolean 2-valued logic 9/5/17. 2-valued logic does not work for nulls

Today s topics. Null Values. Nulls and Views in SQL. Standard Boolean 2-valued logic 9/5/17. 2-valued logic does not work for nulls Today s topics CompSci 516 Data Intensive Computing Systems Lecture 4 Relational Algebra and Relational Calculus Instructor: Sudeepa Roy Finish NULLs and Views in SQL from Lecture 3 Relational Algebra

More information

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

Lecture Notes for 3 rd August Lecture topic : Introduction to Relational Model. Rishi Barua Shubham Tripathi Lecture Notes for 3 rd August 2011 Lecture topic : Introduction to Relational Model Rishi Barua 09010141 Shubham Tripathi 09010148 Example of a relation. Attribute (Column) ID Name Department Salary (Rs)

More information

Incomplete Information: Null Values

Incomplete Information: Null Values Incomplete Information: Null Values Often ruled out: not null in SQL. Essential when one integrates/exchanges data. Perhaps the most poorly designed and the most often criticized part of SQL:... [this]

More information

Chapter 5 Relational Algebra. Nguyen Thi Ai Thao

Chapter 5 Relational Algebra. Nguyen Thi Ai Thao Chapter 5 Nguyen Thi Ai Thao thaonguyen@cse.hcmut.edu.vn Spring- 2016 Contents 1 Unary Relational Operations 2 Operations from Set Theory 3 Binary Relational Operations 4 Additional Relational Operations

More information

Database Management Systems Paper Solution

Database Management Systems Paper Solution Database Management Systems Paper Solution Following questions have been asked in GATE CS exam. 1. Given the relations employee (name, salary, deptno) and department (deptno, deptname, address) Which of

More information

Database Management System (15ECSC208) UNIT I: Chapter 2: Relational Data Model and Relational Algebra

Database Management System (15ECSC208) UNIT I: Chapter 2: Relational Data Model and Relational Algebra Database Management System (15ECSC208) UNIT I: Chapter 2: Relational Data Model and Relational Algebra Relational Data Model and Relational Constraints Part 1 A simplified diagram to illustrate the main

More information

Chapter 2: Intro to Relational Model

Chapter 2: Intro to Relational Model Non è possibile visualizzare l'immagine. Chapter 2: Intro to Relational Model Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Example of a Relation attributes (or columns)

More information

Relational Model and Algebra. Introduction to Databases CompSci 316 Fall 2018

Relational Model and Algebra. Introduction to Databases CompSci 316 Fall 2018 Relational Model and Algebra Introduction to Databases CompSci 316 Fall 2018 2 Announcements (Thu. Aug. 30) Sign up for Piazza, NOW! Homework #1 to be posted today; due in 2½ weeks Sign up for Gradiance

More information

Let s briefly review important EER inheritance concepts

Let s briefly review important EER inheritance concepts Let s briefly review important EER inheritance concepts 1 is-a relationship Copyright (c) 2011 Pearson Education 2 Basic Constraints Partial / Disjoint: Single line / d in circle Each entity can be an

More information

Chapter 2 Introduction to Relational Models

Chapter 2 Introduction to Relational Models CMSC 461, Database Management Systems Spring 2018 Chapter 2 Introduction to Relational Models These slides are based on Database System Concepts book and slides, 6th edition, and the 2009 CMSC 461 slides

More information

Relational Algebra. Algebra of Bags

Relational Algebra. Algebra of Bags Relational Algebra Basic Operations Algebra of Bags What is an Algebra Mathematical system consisting of: Operands --- variables or values from which new values can be constructed. Operators --- symbols

More information

Relational Algebra. Study Chapter Comp 521 Files and Databases Fall

Relational Algebra. Study Chapter Comp 521 Files and Databases Fall Relational Algebra Study Chapter 4.1-4.2 Comp 521 Files and Databases Fall 2010 1 Relational Query Languages Query languages: Allow manipulation and retrieval of data from a database. Relational model

More information

Relational Algebra. Procedural language Six basic operators

Relational Algebra. Procedural language Six basic operators Relational algebra Relational Algebra Procedural language Six basic operators select: σ project: union: set difference: Cartesian product: x rename: ρ The operators take one or two relations as inputs

More information

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

Sets MAT231. Fall Transition to Higher Mathematics. MAT231 (Transition to Higher Math) Sets Fall / 31 Sets MAT231 Transition to Higher Mathematics Fall 2014 MAT231 (Transition to Higher Math) Sets Fall 2014 1 / 31 Outline 1 Sets Introduction Cartesian Products Subsets Power Sets Union, Intersection, Difference

More information

Database Applications (15-415)

Database Applications (15-415) Database Applications (15-415) Relational Algebra Lecture 5, January 24, 2016 Mohammad Hammoud Today Last Session: The relational model Today s Session: Relational algebra Relational query languages (in

More information

CS34800 Information Systems. The Relational Model Prof. Walid Aref 29 August, 2016

CS34800 Information Systems. The Relational Model Prof. Walid Aref 29 August, 2016 CS34800 Information Systems The Relational Model Prof. Walid Aref 29 August, 2016 1 Chapter: The Relational Model Structure of Relational Databases Relational Algebra Tuple Relational Calculus Domain Relational

More information

Relational Algebra 1

Relational Algebra 1 Relational Algebra 1 Relational Query Languages v Query languages: Allow manipulation and retrieval of data from a database. v Relational model supports simple, powerful QLs: Strong formal foundation based

More information

Relational Algebra. Chapter 4, Part A. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1

Relational Algebra. Chapter 4, Part A. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Relational Algebra Chapter 4, Part A Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Relational Query Languages Query languages: Allow manipulation and retrieval of data from a database.

More information

Relational Model and Relational Algebra

Relational Model and Relational Algebra Relational Model and Relational Algebra CMPSCI 445 Database Systems Fall 2008 Some slide content courtesy of Zack Ives, Ramakrishnan & Gehrke, Dan Suciu, Ullman & Widom Next lectures: Querying relational

More information

CHAPTER 1: INTEGERS. Image from CHAPTER 1 CONTENTS

CHAPTER 1: INTEGERS. Image from  CHAPTER 1 CONTENTS CHAPTER 1: INTEGERS Image from www.misterteacher.com CHAPTER 1 CONTENTS 1.1 Introduction to Integers 1. Absolute Value 1. Addition of Integers 1.4 Subtraction of Integers 1.5 Multiplication and Division

More information