Question

In: Computer Science

Given the following schema, write the Relational Algebra and SQL statements for the given conditions:Depositor (customer_name,...

Given the following schema, write the Relational Algebra and SQL statements for the given conditions:Depositor (customer_name, account_number) Borrower (customer_name, loan_number) Loan ( branch_name, loan_number, amount) Account (branch_name, account_number, balance) Branch(branch_name, branch_city, assets) Customer (customer_name, customer_street, customer_city) 1. Find all the customers who have a loan and an account 2. Find the minimum account balance at the Downtown branch. 3. Find the number of tuples in the customer relation. 4. Find the names of all the account numbers and the branch names whose balance is over BD1000. 5. Find the sum of the loans whose branch name is Mianus. 6. Find the number of customers who have a loan. 7. Find the maximum amount of loan taken by a customer. 8. Find the names of the branches and their branch cities whose assets are greater than 50000 and less than 80000.

Solutions

Expert Solution

Solution:

1: Find all the customers who have a loan and an account

Relational Algebra :   ∏customer_name (Borrower) ∩ ∏customer_name (Depositor)

SQL: select distinct customer_name from Borrower as b1
where exists (select customer_name from Depositor as b2
where b1.customer_name = b2.customer_name);

2: Find the minimum account balance at the Downtown branch.

Answer :

Relational Algebra : gmin(balance)branch_name="Downtown"(Account))

SQL: select min(balance) from Account where branch_name="Downtown";

3 : Find the number of tuples in the customer relation

Answer: Relation Algebra : gcount(*)(Customer)

SQL select count(*) from Customer ;

4: Find the names of all the account numbers and the branch names whose balance is over BD1000.

Answer: Relationall Algebra : ∏customer_name, branch_name( σbalance>1000(DepositorAccount) )

SQL : Select customer_name, branch_name

From Depositor natural join Account Where balance>1000;

5 : Find the sum of the loans whose branch name is Mianus.

Relational Alegbra :  gsum(amount)branch_name="Mianus" (Loan))

SQL : select sum(amount) from Loan where branch_name="Mianus" ;

6:  Find the number of customers who have a loan .

Answer :

Relational Algebra : gcount(customer_name)(borrowerloan)

SQL: select distinct count(customer_name) from borrower natural join loan ;

7: Find the maximum amount of loan taken by a customer.

Relational Algebra : gmax(amount)(Loan Customer)

SQL: select max(amount) from loan natural join customer ;

8: Find the names of the branches and their branch cities whose assets are greater than 50000 and less than 80000.

Answer : Relational Algebra :  ∏branch_name,branch_cityasset>50000 AND asset< 80000(Branch))

SQL : select branch_name,branch_city where asset between 50000 and 80000;

Hope you understood the answers for any queries please write in the coment section.


Related Solutions

Given the following relational schema, write queries in SQL to answer the English questions. There is...
Given the following relational schema, write queries in SQL to answer the English questions. There is a shipment database on the MySQL server. You can also use the DDL for MySQL. You must only submit the SQL for your answers but you can include the query output as well to help the TA with marking. Customer(cid: integer, cname: string, address: string, city: string, state: string) Product(pid: integer, pname: string, price: currency, inventory: integer) Shipment(sid: integer, cid: integer, shipdate: Date/Time) ShippedProduct(sid:...
Given the following relational schema, write queries in SQL to answer the English questions. There is...
Given the following relational schema, write queries in SQL to answer the English questions. There is a shipment database on the MySQL server. You can also use the DDL for MySQL. You must only submit the SQL for your answers but you can include the query output as well to help the TA with marking. Customer(cid: integer, cname: string, address: string, city: string, state: string) Product(pid: integer, pname: string, price: currency, inventory: integer) Shipment(sid: integer, cid: integer, shipdate: Date/Time) ShippedProduct(sid:...
Write SQL queries for the following statements based on Employees table whose schema is given below:...
Write SQL queries for the following statements based on Employees table whose schema is given below: (Employee_ID,First_Name,Last_Name,Email,Phone_Number,Hire_Date,Job_ID,Salary, Manager_Id, Department_Id) a. Create the given table along with the following constraints: Phone_Number should not be left undefined, salary should be between 10000 and 20000, employee_id should uniquely identify rows and should not be left undefined. User-defined names should be given to constraints. b.  Display each employee’s last name, hire date and salary review date (which is the date after six months of service)....
Given the below relational algebra expressions, use domain and tuple relational calculus to specify them: a....
Given the below relational algebra expressions, use domain and tuple relational calculus to specify them: a. σx=z ( R(a,b,c) ) b. πx,y ( R(x,y,z) ) c. R(x, y) / S(x) d. R(a,b,c) ∪  S(a,b,c) e. R(a,b,c) – S(a,b,c) f. R(d,e,f) ∩ S(d,e,f) g. R(x,y,z) × S(f,g,t)
Using the following schema, write a SQL query to satisfy the question: What are the names...
Using the following schema, write a SQL query to satisfy the question: What are the names of the suppliers of 'Pith_helmet' sold in a department managed by 'Andrew'? Schema: Sale (saleno, saleqty, itemno, dname) Supplier (splno, splname) Item (itemno, itemname, itemtype, itemcolor) Department (deptname, deptfloor, deptphone, empno) Delivery (delno, delqty, itemnum, dptname, splno) Employee (empno, empfname, empsalary, departname, bossno)
• Relational Schema Create a relational database schema consisting of the four relation schemas representing various...
• Relational Schema Create a relational database schema consisting of the four relation schemas representing various entities recorded by a furniture company.   Write CREATE TABLE statements for the following four relation schemas. Define all necessary attributes, domains, and primary and foreign keys. Customer(CustomerID, Name, Address) FullOrder(OrderID, OrderDate, CustomerID) Request(OrderID, ProductID, Quantity) Product(ProductID, Description, Finish, Price) You should assume the following: Each CustomerID is a number with at most three digits, each OrderID is a number with at most five digits,...
Write the following questions as queries in RELATIONAL ALGEBRA. Use only the operators discussed in class...
Write the following questions as queries in RELATIONAL ALGEBRA. Use only the operators discussed in class (select, project, Cartesian product, join, union, intersection, set difference and renaming). The following database schema is given: ATHLETE(name,age,height,weight,country) RACE(id,location,date,time-start,distance) COMPETES(aname,rid,time,position) where ATHLETE has information about runners (their name, age, height, weight, and nationality); RACE has information about races (id, location, date when it’s held, time it starts, and distance ran); and COMPETES keeps track of which runners run on with race, the time it...
Write the following questions as queries in Relational Algebra. Use only the operators discussed in class...
Write the following questions as queries in Relational Algebra. Use only the operators discussed in class (select, project, Cartesian product, join, union, intersection, set difference and renaming —in particular, no outer joins or aggregations). Type your answers. If you can’t find Greek letters in your word processor, you can simply write out the operator, all uppercase (i.e. ’SELECT’). Please use renaming consistently, as indicated in the handout. Before starting, make sure you understand the schema of the database. If you...
Question 2: consider the following library relational database schema Write a program segment to retrieves the...
Question 2: consider the following library relational database schema Write a program segment to retrieves the list of books that became overdue yesterday and that prints the book title and borrower name for each. 1- Use JDBC with Java as the host language
Listed below is the relational database schema for an online store(SQL/Java): MEMBER(last_name, first_name, email, password, user,street,...
Listed below is the relational database schema for an online store(SQL/Java): MEMBER(last_name, first_name, email, password, user,street, city, state, zip, card_type, card_no, expiration, name_on_card) book_SALE(listing_no, seller, isbn, condition, price) ORDERS(order_no, buyer, order_date, tot) ITEM(order_no, listing_no) BOOK(isbn, title, author, edition, publisher, keywords) The bold attribute(s) in a relation is the primary key of that relation. The italized attributes in some relations denote foreign keys. The seller attribute in the book_SALE relation is a foreign key to the user attribute in the MEMBER...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT