You are on page 1of 6

Problem Number: 01

Problem title:
Consider the banking database bank consisting of the following tables
where the primary keys are underlined.
branch (branch_name,branch_city,assest)
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)
Write down the SQL, expressions for the following queries:
a)
b)
c)
d)

Find all customers who have account but no loan in the bank.
Delete all loan amount between 10000/-and 20000/-.
Add and record in the database using a form.
Display your result a query on a report.

Entity-Relationship (E-R) Diagram:

Database name:bank
Data-definition language (DDL):
CREATE TABLE account (
account_number varchar (255) NOT NULL,
branch_name varchar(255) NOT NULL,
balance decimal (10,0) NOT NULL,
PRIMARY KEY (account_number));
CREATE TABLE borrower(
customer_name varchar(255) NOT NULL,
loan_number varchar(255) NOT NULL,
PRIMARY KEY (customer_name, loan_number));
CREATE TABLE branch (
branch_name varchar (255) NOT NULL,
branch_city varchar (255) NOT NULL,
assets decimal (10,0) NOT NULL,
PRIMARY KEY (branch_name));
CREATE TABLE customer (
customer_name varchar (255) NOT NULL,
customer-city varchar (255) NOT NULL,
customer_street varchar (255) NOT NULL,
PRIMARY KEY (customer_name));
CREATE TABLE depositor (
customer_name
varchar (255) NOT NULL,
account_number varchar (255) NOT NULL,
PRIMARY KEY (customer_name , account_number));
CREATE TABLE loan (
loan_number varchar (255) NOT NULL,
branch_name varchar (255) NOT NULL,
amount decimal (10,0) NOT NULL,
PRIMARY KEY (loan_number) );

Query:
a.

customer_name FROM depositor


customer_name NOT IN (select customer_name from
borrower);
b. DELETE FROM loan
WHERE amount between '13000' and '20000';
c. <html>
<body>
SELECT
WHERE

<form action="" method="post">


BranchName: <input type="text" name="branchname"/>
BranchCity: <input type="text" name="branchcity"/>
Assets: <input type="text" name="assets"/>
<input type="submit"/>
</form>
</body>
</html>
<?php
if( isset($_POST['branchname']) && isset($_POST['branchcity']) &&
isset($_POST['assets'])){
$conn = oci_connect('system', 'root123', '//localhost/orcl');
// Check connection
if (!$conn) {
$e = oci_error();
trigger_error(htmlentities($e['connection not established'],
ENT_QUOTES), E_USER_ERROR);
}
$sql="INSERT INTO branch(branchName, branchcity, assets)VALUES
('$_POST[branchName]','$_POST[branchcity]','$_POST[assets]')";
$stid = oci_parse($conn,$sql);
oci_execute($stid);
echo "1 record added";
}
?>

Problem Number: 02

Problem Title:
Consider the banking database emp consisting of the following tables
where the primary keys are underlined.
employee (employee_name, street, city)
works (employee_name, company_name, salary)
company (company_name, city)
manages(employee_name, manager_name)
Write down the SQL expressions for the following queries.
a) Find the names, cities and salaries of all employees who work for Prime
Bank.
b) Find the total salaries of each company.
c) Add and record in the database using a form.
d) Display your result a query on a report.

Entity-Relationship (E-R) Diagram:

Database Name: emp


Data Definition Language (DDL):
CREATE DATABASE emp;
USE emp;
CREATETABLE company (
company_name varchar(255) NOTNULL,
city varchar(255) NOTNULL,
PRIMARYKEY (company_name));
CREATETABLE employee (
employee_name varchar(255) NOTNULL,
street varchar(255) NOTNULL,
city varchar(255) NOTNULL,
PRIMARYKEY (employee_name));
CREATETABLE managers (
employee_name varchar(255) NOTNULL,
manager_name varchar(255) NOTNULL,
PRIMARYKEY (employee_name));
CREATETABLE works (
employee_name varchar(255) NOTNULL,
company_name varchar(255) NOTNULL,
salary decimal(10,0) NOTNULL,
PRIMARYKEY (employee_name,company_name));

Query:
a. SELECT e.employee_name,city,salary
FROM employee e, works w
WHERE e.employee_name=w.employee_name
AND company_name='Prime Bank';
b. SELECTSUM(salary) AS salary
FROM works
GROUP BY company_name;
c.
<html>
<body>
<form action="" method="post">
Employee Name: <input type="text" name="employeename"/>
Street: <input type="text" name="street"/>
City: <input type="text" name="city"/>
<input type="submit"/>
</form>
</body>

</html>
<?php
if( isset($_POST['employeename']) && isset($_POST['street']) &&
isset($_POST['city'])){
$conn = oci_connect('system', 'root123', '//localhost/orcl');
// Check connection
if (!$conn) {
$e = oci_error();
trigger_error(htmlentities($e['connection not established'],
ENT_QUOTES), E_USER_ERROR);
}
$sql="INSERT INTO employee(employeeName, street,
city)VALUES
('$_POST[employeename]','$_POST[street]','$_POST[city]')";
$stid = oci_parse($conn,$sql);
oci_execute($stid);
echo "1 record added";
}
?>

You might also like