Relational Modelcse.iitrpr.ac.in/ckn/courses/s2015/w1.pdfSummary • Relational model – Collection of relations or tables – Schema of a relation refers its logical design – Instance

Post on 01-Apr-2020

2 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

Transcript

Relational Model

Department of Computer Science and EngineeringIndian Institute of Technology Ropar

Narayanan (CK) Chatapuram Krishnan!

CSL 451 Introduction to Database Systems

Summary•  Relational model

–  Collection of relations or tables–  Schema of a relation refers its logical design–  Instance of a relation refers to its contents at a certain point in time

•  Schema of a relation–  Attributes (atomicity)–  Type of the attributes (domain)–  Constraints on the relation

•  Superkey: a set of one or more attributes whose values are guaranteed to identify tuples in the relation uniquely–  Candidate key – minimal superkey–  Primary key – the chosen candidate key of a relation–  Foreign key – set of attributes in the referencing relation that constitute

the primary key in the referenced relation15/01/15! Department of Computer Science and Engineering !

Indian Institute of Technology Ropar! 2!

Summary•  Schema Diagram–  Pictorial depiction of the schema of a database

•  Relational query languages–  Define a set of operations that operate on

tables(relations), and output tables(relations) as their results

•  Relational Algebra–  An example of the set of operations–  Selection–  Projection–  Natural Join–  Cartesian Product–  Union

15/01/15! Department of Computer Science and Engineering !Indian Institute of Technology Ropar! 3!

Example of a Schema

15/01/15! Department of Computer Science and Engineering !Indian Institute of Technology Ropar! 4!

2.1 Consider the following relational databaseemployee (person_name, street, city)

works (person_name, company_name, salary)company (company_name, city)

What are the appropriate primary keys?

15/01/15! Department of Computer Science and Engineering !Indian Institute of Technology Ropar! 5!

2.2 Consider the foreign key constraint from the dept_name attribute of instructor to the department relation. Give examples of inserts and deletes to these relations, which can cause a violation of the foreign key constraint

15/01/15! Department of Computer Science and Engineering !Indian Institute of Technology Ropar! 6!

2.3 Consider the time_slot relation. Given that a particular time slot can meet more than once in a week, explain why day and start_time are part of the primary key of this relation, while end_time is not?

15/01/15! Department of Computer Science and Engineering !Indian Institute of Technology Ropar! 7!

2.4 In the instance of instructor, no two instructors have the same name. From this can we conclude that name can be used as a superkey (or primary key) of instructor?

15/01/15! Department of Computer Science and Engineering !Indian Institute of Technology Ropar! 8!

2.5 What is the result of first performing the cross product of student and advisor, and then performing a selection operation on the result with the predicate s_id = ID?

15/01/15! Department of Computer Science and Engineering !Indian Institute of Technology Ropar! 9!

2.6.a Explain in words what the expression does

15/01/15! Department of Computer Science and Engineering !Indian Institute of Technology Ropar! 10!

�year�2009(takes) ./ student

2.6.b Explain in words what the expression does

15/01/15! Department of Computer Science and Engineering !Indian Institute of Technology Ropar! 11!

�year�2009(takes ./ student)

2.6.c Explain in words what the expression does

15/01/15! Department of Computer Science and Engineering !Indian Institute of Technology Ropar! 12!

⇧ID,name,course id

(student ./ takes)

2.7.a Consider the following relational databaseemployee (person_name, street, city)

works (person_name, company_name, salary)company (company_name, city)

Give a relational algebra expression for – finding the names of all employees who live in city “Miami”

15/01/15! Department of Computer Science and Engineering !Indian Institute of Technology Ropar! 13!

2.7.b Consider the following relational databaseemployee (person_name, street, city)

works (person_name, company_name, salary)company (company_name, city)

Give a relational algebra expression for – finding the names of all employees whose salary is greater than $100,000.

15/01/15! Department of Computer Science and Engineering !Indian Institute of Technology Ropar! 14!

2.7.c Consider the following relational databaseemployee (person_name, street, city)

works (person_name, company_name, salary)company (company_name, city)

Give a relational algebra expression for – finding the names of all employees who live in “Miami” and whose salary is greater than $100,000.

15/01/15! Department of Computer Science and Engineering !Indian Institute of Technology Ropar! 15!

2.9 Consider the following bank databasebranch (branch_name, branch_city, assets)

customer (customer_name, customer_street, customer_city)loan(loan_number, branch_name, amount)borrower (customer_name, loan_number)

account (account_number, branch_name, balance)depositor (customer_name, account_number)

a.  What are the appropriate primary keys?b.  Given your choice of primary keys, identify appropriate

foreign keys.

15/01/15! Department of Computer Science and Engineering !Indian Institute of Technology Ropar! 16!

2.8 Consider the following bank databasebranch (branch_name, branch_city, assets)customer (customer_name, customer_street, customer_city)loan(loan_number, branch_name, amount)borrower (customer_name, loan_number)account (account_number, branch_name, balance)depositor (customer_name, account_number)

Give an expression in relational algebra fora.  Find the names of all branches located in “Chicago”

15/01/15! Department of Computer Science and Engineering !Indian Institute of Technology Ropar! 17!

2.8 Consider the following bank databasebranch (branch_name, branch_city, assets)customer (customer_name, customer_street, customer_city)loan(loan_number, branch_name, amount)borrower (customer_name, loan_number)account (account_number, branch_name, balance)depositor (customer_name, account_number)

Give an expression in relational algebra forb.  Find the names of all borrowers who have a loan in branch

“Downtown”

15/01/15! Department of Computer Science and Engineering !Indian Institute of Technology Ropar! 18!

2.13 Consider the following bank databasebranch (branch_name, branch_city, assets)customer (customer_name, customer_street, customer_city)loan(loan_number, branch_name, amount)borrower (customer_name, loan_number)account (account_number, branch_name, balance)depositor (customer_name, account_number)

Give an expression in relational algebra fora.  Find all loan numbers with a loan value greater than $10,000

15/01/15! Department of Computer Science and Engineering !Indian Institute of Technology Ropar! 19!

2.13 Consider the following bank databasebranch (branch_name, branch_city, assets)customer (customer_name, customer_street, customer_city)loan(loan_number, branch_name, amount)borrower (customer_name, loan_number)account (account_number, branch_name, balance)depositor (customer_name, account_number)

Give an expression in relational algebra forb.  Find the names of all depositors who have an account with a

value greater than $6,000

15/01/15! Department of Computer Science and Engineering !Indian Institute of Technology Ropar! 20!

2.13 Consider the following bank databasebranch (branch_name, branch_city, assets)customer (customer_name, customer_street, customer_city)loan(loan_number, branch_name, amount)borrower (customer_name, loan_number)account (account_number, branch_name, balance)depositor (customer_name, account_number)

Give an expression in relational algebra forc.  Find the names of all depositors who have an account with a

values greater than $6,000 at the “Uptown” branch.

15/01/15! Department of Computer Science and Engineering !Indian Institute of Technology Ropar! 21!

2.10 Consider the advisor relation, with s_id as the primary key of advisor. Suppose a student can have more than one advisor. Then, would s_id still be a primary key of the advisor relation? If not, what should the primary key of advisor be?

15/01/15! Department of Computer Science and Engineering !Indian Institute of Technology Ropar! 22!

2.11 Describe the differences in the meaning between the terms relation and relation schema

15/01/15! Department of Computer Science and Engineering !Indian Institute of Technology Ropar! 23!

2.14 List two reasons why null values might be introduced into the database

15/01/15! Department of Computer Science and Engineering !Indian Institute of Technology Ropar! 24!

top related