Anda di halaman 1dari 6

Problem Number: 05

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) Find the name and loan number of all customer who have a loan from the
bank.
b) Find the number of depositor for each branch.
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: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

FROM

borrower;

b. SELECT COUNT( DISTINCT customer_name) AS Customer Name


ROM depositor D,account A
WHERE D.account_number=A.account_number
GROUP BY branch_name;
c. <html>
<body>
<form action="" method="post">
Branch Name: <input type="text" name="branchname"/>
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: 06
Problem Title:
Consider the following company database consisting of the tables where the
primary keys are underlined.
lives(person_name, street, city)
works (person_name,company_name, salary)

location (company_name, salary)


manages (person_name, company_name,salary)
Write down the SQL expressions for the following queries.
a)
b)
c)
d)

Modify the database to change Rahims living city to a new one.


Find the number of tuples in works in relations.
Add and record in the database using a form.
Display your result a query on a report.

Entity-Relationship (E-R) Diagram:

Database Name: company


Data Definition Language (DDL):
CREATE DATABASE company;
USE company;
CREATETABLE lives (
person_name varchar(255) NOTNULL,
street varchar(255) NOT NULL,
city varchar(255) NOTNULL,
PRIMARYKEY (person_name));
CREATETABLE works (
person_name varchar(255) NOTNULL,
company_namevarchar(255) NOTNULL,
salarynumberNOTNULL,
PRIMARYKEY (company_name));
CREATETABLE location (
company_name varchar(255) NOTNULL,
salarynumberNOTNULL,
PRIMARYKEY (company_name));
CREATETABLE manages (
person_name varchar(255) NOTNULL,
company_name varchar(255) NOTNULL,
salary numberNOTNULL,
PRIMARYKEY (person_name);

Query:
a) UPDATE lives set city='dhanmondi'
WHERE person_name='Rahim';
b) SELECTCOUNT(*) AS Tuples
FROM works w,location l
WHEREw.company_name=l. company_name;
c) <html>
<body>
<form action="" method="post">
Person Name:<input type="text" name="personname"/>
Street: <input type="text" name="street"/>
City:<input type="text" name="city"/>
<input type="submit"/>
</form>
</body>
</html>
<?php
if( isset($_POST['prsonname']) && 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 lives(prson_name, street, city)VALUES
('$_POST[personname]','$_POST[street]','$_POST[city]')";
$stid = oci_parse($conn,$sql);
oci_execute($stid);
echo "1 record added";
}
?>

Anda mungkin juga menyukai