2. Considering the following schema of a bank database,
Branch (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) Identify the candidate keys and the primary key of each
relation. [15 points]
(b) Draw a schema diagram for the database. Make sure to underline
the primary keys. [15 points]
(c) Considering the schema above, write relational expressions for
the following sentences [15 points]
Find all customers from ‘Kent’ city.
Find the names of all borrowers with a loan amount greater than
$5000
Find the names of all depositors who have an account with a balance
greater than $9,000 at the “Kent” branch.
(d) What is Cartesian-product? Explain its importance in the
relational data model. [10 points]
a. Every primary key is a candidate key and there can be many candidate key in a relation but there will be only one primary key in every relation. Candidate key can be one simple attribute or more than one attributes (combined). Combined attributes as a candidate key can be written in {}.
| Entity | Primary Key | Candidate Key |
| Branch | branch_name |
branch_name, |
| customer | customer_name | customer_name, {customer_name, customer_street} |
| loan | loan_number | loan_number, {loan_number, branch_name} |
| borrower | loan_number | loan_number, {customer_name, loan_number} |
| account | account_number | account_number, {account_number, branch_name} |
| depostier | account_number | account_number, {customer_name, account_number} |
b.
c.
π customer_name (σ customer_city = 'Kent'(customers))
π customer_name (σ borrower.loan_number = loan.loan_number AND amount > 5000 (borrower X loan))
π customer_name (σ account.account_number = depositer.account_number AND balance > 9000 AND branch_name = "Kent" (account X depositer))
d. Cartesian-product is multiple of
two table. Every row of table 1 will be combined with all the rows
of table 2, if Table 1 have 2 rows and Table 2 have 3 rows then
there cartesian-product will have 2x3 = 6 row
(rows get multiplied). The rows of
cartesian-product of table 1 and table 2 will contain all the
columns from both the table, if Table 1 have 3 columns and Table 2
have 2 columns then there cartesian-product will have
3+2 = 5 columns (columns are add
up)
For example:
Table 1(loan): 2 rows and 3 columns
| loan_number | branch_name | amount |
| 123 | Kent | 1500 |
| 124 | Dent | 1600 |
Table 2(depositer): 3 rows and 2 columns
| account_number | customer_name |
| 345 | Tom |
| 346 | Daisy |
| 347 | Harry |
Cartesian-Product (loan x depositer): 6 rows and 5 columns
| loan_number | branch_name | amount | account_number | customer_name |
| 123 | Kent | 1500 | 345 | Tom |
| 123 | Kent | 1500 | 346 | Daisy |
| 123 | Kent | 1500 | 347 | Harry |
| 124 | Dent | 1600 | 345 | Tom |
| 124 | Dent | 1600 | 346 | Daisy |
| 124 | Dent | 1600 | 347 | Harry |
Cartesian-product is important, sometimes when select command is done and when columns are required from both the table, then this is done using cartesian-product and this operation is also known as joining. This helps joining the table in ralational data model and helps to select things from both the table. It denotes by symbol 'X'.
2. Considering the following schema of a bank database, Branch (branch_name, branch_city, assets) customer (customer_name, customer_street,...
1. Given the following BANKING database, formulate a Relational Algebra expression for each of the following questions. SELECT should be performed before any JOIN operation. Notation: use the symbol S for SELECT, P for PROJECT, J for INNER JOIN, * for NATURAL JOIN, LJ for LEFT JOIN, RJ for RIGHT JOIN, R for RENAME, and F for FUNCTION. Please type your answer; hand-writing is not accepted. branch(branch_name, branch_city, assets) customer (customer_name, customer_street, customer_city) loan (loan_number, branch_name, amount) borrower (customer_name, loan_number)...
Specify relational calculus expression for the following
descriptions on the Library database schema shown in Figure
4.6.
a) Retrieve Publishers’ name and phone number whose books where
borrowed from Baltimore Branch.
b) List the book title, book id and branch name with less than
10 copies
c) List customer card number, customer name, branch name and
book title for books which are currently on loan.
BOOK Book id Title Publisher_name BOOK_AUTHORS Book idAuthor name PUBLISHER Name Address Phone BOOK COPIES...
The following figure shows an ER schema for a database that can be used to keep track of transport ships and their locations for maritime authorities. Map this schema into a relational schema and specify all primary keys and foreign keys. Use arrows to specify the relationships. Use descriptive names for foreign keys.
Given the following relational database schema (primary keys are bold and underlined). Answer questions 2.1 to 2.4 Orders(orderld, customerld, dateOrdered, dateRequired, status) Customer(customerld, customerLastName, customerStreet, customerCity, customerState, customer Lip OrderDetails(orderld.productld, quantity, lineNumber, amount) Products(productld, name, description, quantity, unitPrice) Account(accountNumber, customerld, dateOpened, creditCard, mailingStreet, mailingCity, mailingState, mailingZip) 2.1 (2 Points) List all possible foreign keys. For each foreign key list both the referencing and referenced relations. 2.2 (2 Points) Devise a reasonable database instance by filling the tables with data of...
Write SQL statements to answer the following questions using Assignment 3’s schema (tables from part 1). 1- Find how many branches had have loans over $2000.00. 2- For each branch, find the most expensive loan. Your output should include Branch Id, loan amount for the highest loan for that Branch. 3- Find how many accounts there are for each customer. The output should include customer id and number of accounts for that customer. 4- Find the total balance amount of...
Consider the following relational database to manage concert and ticket sales. The relations are artist, concert, venue, seat, ticket, and fan. The schemas for these relations (with primary key attributes underlined) are: Artist-schema = (artistname, type, salary) Concert-schema = (artistname, date, venuename, artistfees) Venue-schema = (venuename, address, seating_capacity) Seat-schema=(venuename, row, seatnumber) Ticket-schema = (fanID, date, venuename, row, seatnumber) Fan-schema = (fanID, name, address, creditcardno) Where: • artistname is a unique name for the artist (because of trademark/copyright rules no two...
For all problems, use the following schema: Musician(id, first_name, last_name, instrument, band_id) Band(id, name, years_together) Show(id, venue_id, date) Played_in(band_id, show_id) Venue(id, name, address) Album(id, name, year, band_id, genre_id) Genre(id, name, description) Song(id, name, album_id) Primary keys are in bold, foreign keys are in italics. For each problem, write a query once using relational algebra, and again using SQL. 12. Find the names of all bands that have a member who plays "Guitar", OR have a member that plays "Keyboard". 13....
Intro to database systems question:
Question2 (20 points, 5 points each) Consider the following relational schema as part of a university database Prof(sin, pname, o_ce, age, sex, specialty, dept did) Dept(did, dname, budget, num majors, chair sin) Assume the following queries are the most common queries in the workload for this university and they are almost equivalent in frequency and importance Assume that both B+ trees and hashed indexes are supported by the DBMS and that both single and multiple-attribute...
The following relational schema is given for a Pokemon Database: Pokemon (PID, PName) Type (TID, TName) Trainer (SSN, Name, Surname) InType (PID, TID) StrongAgainst (TID_Strong, TID_Weak) Owns (SSN, PID, Nickname, Level, Height, Weight, Catch_Date) SpecializedIn (SSN, TID) In this database, Pokemon (Imaginary creatures, short for “Pocket Monsters”) are stored in the entity set Pokemon, with a unique PID and PName. Pokemon types are stored in the entity set Type, with a unique TID and TName. Pokemon trainers are stored in...
May I ask the SQL code as follows? The relational database moviedb has the following database schema: Movie(title, production year, country, run time, major genre) primary key : {title, production year} Person(id, first name, last name, year born) primary key : {id} Award(award name, institution, country) primary key : {award name} Restriction Category(description, country) primary key : {description, country} Director(id, title, production year) primary key : {title, production year} foreign keys : [title, production year] ⊆ Movie[title, production year] [id]...