Sei sulla pagina 1di 6

Problem Number: 03

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.
Find the average account balance at each branch.
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) SELECT customer_name FROM depositor
customer_name NOT IN (select customer_name from borrower);
b) SELECT AVG(balance) AS Average FROM account group by branch_name;
WHERE

c) <html>
<body>

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


Branch Name: <input type="text" name="branchname"/>
Branch City: <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: 04
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, street and cities of all employee who work form Prime Bank
Ltd, and earn more Tk 10,000/-.
b) Find all employee in the database who earn more than each employee of
Trust Bank Ltd.
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,street,city
FROM employee e,works w
WHERE e.employee_name=w.employee_name

AND company_name='Prim

Bank' AND salary>10000;


b. SELECT employee_name FROM works WHERE company_name='Prime
Bank' AND salary>(SELECT MAX(salary) FROM works WHERE
company_name='Prime Bank');
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[employeeame]','$_POST[street]','$_POST[city]')";
$stid = oci_parse($conn,$sql);
oci_execute($stid);
echo "1 record added";
}
?>

Potrebbero piacerti anche