Database Problems 01 02
Database Problems 01 02
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.
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.
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.
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";
}
?>