Presentation is loading. Please wait.

Presentation is loading. Please wait.

Relational Model B.Ramamurthy 5/28/2019 B.Ramamurthy.

Similar presentations


Presentation on theme: "Relational Model B.Ramamurthy 5/28/2019 B.Ramamurthy."— Presentation transcript:

1 Relational Model B.Ramamurthy 5/28/2019 B.Ramamurthy

2 Introduction Relational database theory assist in definition of databases and in efficient processing of databases and in efficient processing of user requests for information from a database. ER model defined the problem and leads us to the tables. Now we need to define, manipulate and use the tables.. Relational model provides the foundation for this. 5/28/2019 B.Ramamurthy

3 Topics for Discussion Structure of Relational database
Relational Algebra Tuple Relational Calculus Domain Relational Calculus Extended Relational-Algebra-Operations Modifications of the Database Views Summary 5/28/2019 B.Ramamurthy

4 Relational Database A relational database consists of a collection of tables, each of which is assigned a unique name. A table will be referred to as a relation in Relational DB. Tuple is the term for row in a table. On to more theoretical stuff … 5/28/2019 B.Ramamurthy

5 Basic Structure Given sets A1, A2, A3…An, a relation r is a subset of
A1 X A2 X A3 X ….X An A relation is a set of n-tuples (a1,a2,a3,..an) where ai Є Ai. Example : if customer-name = {Jones, Smith, Curry, Lindsay} customer-street = {Main, North, Park} customer-city = {Harrison, Rye, Pittsfield} Then r = {(Jones,Main,Harrison), (Smith,North,Rye), {Curry,North,Rye), (Lindsay, Park, Pittsfield)} is a relation over customer-name X customer-street X customer-city 5/28/2019 B.Ramamurthy

6 Relation Schema (This concept is analogous to class, instance of a class in OOP) A1, A2, A3.. An are attributes R = (A1, A2, A3, …An) is a relation schema. Example : Customer-schema = (customer-name, customer-street, customer-city) r(R) is a relation on the relational schema R Example : customer(Customer-schema) 5/28/2019 B.Ramamurthy

7 More Examples Branch-scheme= (banch-name, branch-city,assets)
Relation is a table of specific branches branch-name branch-city assets Downtown Brooklyn Redwood Palo Alto North Town Rye 5/28/2019 B.Ramamurthy

8 Relation Instance Current values (relational instance) of a relation are specified by a table. An element t of r is a tuple: represented by a row in the “relation” table See the above example 5/28/2019 B.Ramamurthy

9 Query Language Language in which user requests information from a database. Categories of languages: procedural, non procedural Pure Languages: Relational algebra Tuple relational calculus Domain relational calculus Pure languages form the basis of query languages. 5/28/2019 B.Ramamurthy

10 Relational Algebra Procedural Language Six fundamental operations
Select Project Union Set difference Cartesian product Rename The operators take two or more relations as inputs and give a new relation as a result. 5/28/2019 B.Ramamurthy

11 Select Operation Select operation selects tuples that satisfy a given predicate. Lowercase sigma is used to denote selection. The predicate appears as subscript to p The argument relation is given in parenthesis. Therefor notation for Select operation is p (r) 5/28/2019 B.Ramamurthy

12 Select: Formal Definition
P ( r ) = {t | t Є r and P(t)} where t is a tuple in r that satisfies P(t) P(t) is a formula in propositional calculus, dealing with terms of the form: <attribute> op <attribute> or constant op represents an operator in { =, <>, > , >=, <=} simple terms can be connected by and, or, not 5/28/2019 B.Ramamurthy

13 Select: Example c Relation r : A B C D   1 7 5 12 3 23 10  
A= B and D > 5 (r ) 23 10 5/28/2019 B.Ramamurthy

14 Project Operation Suppose you are interested in retrieving only a few attributes of a relation. A “Project” operation can be used. It is a unary operation. Basically a vertical subset of a table is returned. Duplicate rows are removed from the result. 5/28/2019 B.Ramamurthy

15 Project: Formal Definition
A1,A2,…Ak ( r ) where A1, A2, …Ak are attribute names and r is a relation name. Result has k columns, each column representing an attribute. 5/28/2019 B.Ramamurthy

16 Project: Example A B C D Relation r :   1 7 5 7 12 3   23 10  
A,B ( r ) 5/28/2019 B.Ramamurthy

17 Union Operation Binary operation. Notation : r U s
Definition: r U s = {t | t Є r or t Є s} Constraints are: 1. r and s must have same arity (same number of attributes) 2. The attribute domains must be compatible (ex: 2 nd column of r is of String type and so should 2nd column of s) 5/28/2019 B.Ramamurthy

18 Union: Example  1  2 s r   2 3 r U s  1   2 1  3 A B A B A B
5/28/2019 B.Ramamurthy

19 Other Important Operations
We discussed Join, Division, Cartesian Product, Rename and Assignment operations. For each of these we studied: 1. The symbol 2. Formal expression 3. An example in tabular form 4. A sample query that needs (or uses) this operation. 5/28/2019 B.Ramamurthy

20 Tuple Relational Calculus
A nonprocedural query language, where each query is of the form { t | P(t) } It is the set of all tuples t such that predicate P is true for t. t is a tuple variable; t[ A] denotes the value of tuple t on attribute A and t  r denotes that tuple t is in relation r. P is a formula similar to that of the predicate calculus. 5/28/2019 B.Ramamurthy

21 Sample Queries {t | t  loan  t[amount] > 1200}
Write the following in tuple relational calculus as well as in relational algebra. Loan numbers such that loan-amount > 1200 Names of all customers who have a loan from the PerryRidge branch. 5/28/2019 B.Ramamurthy

22 Extended Relational Algebra Operations
Generalized projection: Apply arithmetic (or any) function to the regular projection. Example : Credit info of customers. Outer Join: Extension of join that deals with missing information. Lossless join. We have left outer join and right outer join. Aggregate functions: to take a collection of values and return a single value. Example : sum of a column. 5/28/2019 B.Ramamurthy

23 Modification of the database
Deletion, insertion, updating : all these major operations are actual a collection of lower level operations we have discussed. Views: View definitions will also have only part of the data stored in the table depending on the request. Once again we apply the project , join and other operations we studied. 5/28/2019 B.Ramamurthy

24 Summary A relational database is made up of tables.
Each table is a relation. Each row of a table is a relationship. E-R diagram --> relation-schema--> tables --> RDB Relational operations are used to extract data from the tables. 5/28/2019 B.Ramamurthy


Download ppt "Relational Model B.Ramamurthy 5/28/2019 B.Ramamurthy."

Similar presentations


Ads by Google