0% found this document useful (0 votes)
2 views19 pages

Dbms SQL Assignment 3 Answer

The document outlines the structure and data for an Account Management System, including the creation of tables for customers, branches, accounts, transaction details, and loans using DDL and DML statements. It provides example records for each table and includes various SQL queries to manipulate and retrieve data based on specific requirements. The queries cover updating account balances, displaying customer information, and summarizing account details by branch and transaction types.

Uploaded by

kaifakhtar008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views19 pages

Dbms SQL Assignment 3 Answer

The document outlines the structure and data for an Account Management System, including the creation of tables for customers, branches, accounts, transaction details, and loans using DDL and DML statements. It provides example records for each table and includes various SQL queries to manipulate and retrieve data based on specific requirements. The queries cover updating account balances, displaying customer information, and summarizing account details by branch and transaction types.

Uploaded by

kaifakhtar008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

Classification: Internal

ASSIGNMENT 3:

ACCOUNT MANAGEMENT SYSTEM

Prerequisite: Create the basic structure using DDL and DML statement as shown in exercise:

(CREATE TABLE STRUCTURE WITH GIVEN NAME)

Eg: customer

CREATE TABLE customer

(
Classification: Internal

CUST_ID VARCHAR(6),

FIRST_NAME VARCHAR(30),

MID_NAME VARCHAR(30),

LAST_NAME VARCHAR(30),

CITY VARCHAR(15),

MOBILENO VARCHAR(10),

OCCUPATION VARCHAR(10),

CUST_DOB DATE,

CONSTRAINT customer_custid_pk PRIMARY KEY(CUST_ID)

);

CREATE TABLE branch

BRANCH_ID VARCHAR(6),

BRANCH_NAME VARCHAR(30),

BRANCH_CITY VARCHAR(30),

CONSTRAINT branch_bid_pk PRIMARY KEY(BRANCH_ID)

);

CREATE TABLE account

AC_NUMBER VARCHAR(6),

CUST_ID VARCHAR(6),

BRANCH_ID VARCHAR(6),
Classification: Internal

OPEN_BALANCE NUMBER,

AC_OPEN_DATE DATE,

AC_TYPE VARCHAR(10),

AC_STATUS VARCHAR(10),

CONSTRAINT account_acnumber_pk PRIMARY KEY(AC_NUMBER),

CONSTRAINT account_custid_fk FOREIGN KEY(CUST_ID) REFERENCES customer(CUST_ID),

CONSTRAINT account_bid_fk FOREIGN KEY(BRANCH_ID) REFERENCES branch(BRANCH_ID)

);

CREATE TABLE TRAN_DETAILS

TRAN_NUMBER VARCHAR(6),

AC_NUMBER VARCHAR(6),

TRAN_DATE DATE,

MIDIUM_OF_TRAN VARCHAR(20),

TRAN_TYPE VARCHAR(20),

TRAN_AMOUNT NUMBER,

CONSTRAINT trandetails_tnumber_pk PRIMARY KEY(TRAN_NUMBER),

CONSTRAINT trandetails_acnumber_fk FOREIGN KEY(AC_NUMBER) REFERENCES account(AC_NUMBER)

);

CREATE TABLE LOAN

CUST_ID VARCHAR(6),
Classification: Internal

BRANCH_ID VARCHAR(6),

LOAN_AMOUNT NUMBER,

CONSTRAINT loan_customer_custid_bid_pk PRIMARY KEY(CUST_ID,BRANCH_ID),

CONSTRAINT loan_custid_fk FOREIGN KEY(CUST_ID) REFERENCES customer(CUST_ID),

CONSTRAINT loan_bid_fk FOREIGN KEY(BRANCH_ID) REFERENCES branch(BRANCH_ID)

);

DML STATEMENTS FOR THE SYSTEM:

--Records for the bank customers

INSERT INTO customer


VALUES('C00001','Ramesh','Chandra','Sharma','Delhi','9543198345','Service',to_date('1976-12-06','YYYY-
MM-DD'));

INSERT INTO customer


VALUES('C00002','Avinash','Sunder','Minha','Delhi','9876532109','Service',to_date('1974-10-16','YYYY-
MM-DD'));

INSERT INTO customer


VALUES('C00003','Rahul',null,'Rastogi','Delhi','9765178901','Student',to_date('1981-09-26','YYYY-MM-
DD'));

INSERT INTO customer


VALUES('C00004','Parul',null,'Gandhi','Delhi','9876532109','Housewife',to_date('1976-11-03','YYYY-MM-
DD'));

INSERT INTO customer


VALUES('C00005','Naveen','Chandra','Aedekar','Mumbai','8976523190','Service',to_date('1976-09-
19','YYYY-MM-DD'));

INSERT INTO customer


VALUES('C00006','Chitresh',null,'Barwe','Mumbai','7651298321','Student',to_date('1992-11-06','YYYY-
MM-DD'));

INSERT INTO customer


VALUES('C00007','Amit','Kumar','Borkar','Mumbai','9875189761','Student',to_date('1981-09-06','YYYY-
MM-DD'));
Classification: Internal

INSERT INTO customer


VALUES('C00008','Nisha',null,'Damle','Mumbai','7954198761','Service',to_date('1975-12-03','YYYY-MM-
DD'));

INSERT INTO customer


VALUES('C00009','Abhishek',null,'Dutta','Kolkata','9856198761','Service',to_date('1973-05-22','YYYY-
MM-DD'));

INSERT INTO customer


VALUES('C00010','Shankar',null,'Nair','Chennai','8765489076','Service',to_date('1976-07-12','YYYY-MM-
DD'));

--Records for the bank branches

INSERT INTO branch VALUES('B00001','Asaf ali road','Delhi');

INSERT INTO branch VALUES('B00002','New delhi main branch','Delhi');

INSERT INTO branch VALUES('B00003','Delhi cantt','Delhi');

INSERT INTO branch VALUES('B00004','Jasola','Delhi');

INSERT INTO branch VALUES('B00005','Mahim','Mumbai');

INSERT INTO branch VALUES('B00006','Vile parle','Mumbai');

INSERT INTO branch VALUES('B00007','Mandvi','Mumbai');

INSERT INTO branch VALUES('B00008','Jadavpur','Kolkata');

INSERT INTO branch VALUES('B00009','Kodambakkam','Chennai');

--Records for account master

INSERT INTO account VALUES('A00001','C00001','B00001',1000,to_date('2012-12-15','YYYY-MM-


DD'),'Saving','Active');

INSERT INTO account VALUES('A00002','C00002','B00001',1000,to_date('2012-06-12','YYYY-MM-


DD'),'Saving','Active');

INSERT INTO account VALUES('A00003','C00003','B00002',1000,to_date('2012-05-17','YYYY-MM-


DD'),'Saving','Active');
Classification: Internal

INSERT INTO account VALUES('A00004','C00002','B00005',1000,to_date('2013-01-27','YYYY-MM-


DD'),'Saving','Active');

INSERT INTO account VALUES('A00005','C00006','B00006',1000,to_date('2012-12-17','YYYY-MM-


DD'),'Saving','Active');

INSERT INTO account VALUES('A00006','C00007','B00007',1000,to_date('2010-08-12','YYYY-MM-


DD'),'Saving','Suspended');

INSERT INTO account VALUES('A00007','C00007','B00001',1000,to_date('2012-10-02','YYYY-MM-


DD'),'Saving','Active');

INSERT INTO account VALUES('A00008','C00001','B00003',1000,to_date('2009-11-09','YYYY-MM-


DD'),'Saving','Terminated');

INSERT INTO account VALUES('A00009','C00003','B00007',1000,to_date('2008-11-30','YYYY-MM-


DD'),'Saving','Terminated');

INSERT INTO account VALUES('A00010','C00004','B00002',1000,to_date('2013-03-01','YYYY-MM-


DD'),'Saving','Active');

--Records for transaction details

INSERT INTO TRAN_DETAILS VALUES('T00001','A00001',to_date('2013-01-01','YYYY-MM-


DD'),'Cheque','Deposit',2000);

INSERT INTO TRAN_DETAILS VALUES('T00002','A00001',to_date('2013-02-01','YYYY-MM-


DD'),'Cash','Withdrawal',1000);

INSERT INTO TRAN_DETAILS VALUES('T00003','A00002',to_date('2013-01-01','YYYY-MM-


DD'),'Cash','Deposit',2000);

INSERT INTO TRAN_DETAILS VALUES('T00004','A00002',to_date('2013-02-01','YYYY-MM-


DD'),'Cash','Deposit',3000);

INSERT INTO TRAN_DETAILS VALUES('T00005','A00007',to_date('2013-01-11','YYYY-MM-


DD'),'Cash','Deposit',7000);

INSERT INTO TRAN_DETAILS VALUES('T00006','A00007',to_date('2013-01-13','YYYY-MM-


DD'),'Cash','Deposit',9000);

INSERT INTO TRAN_DETAILS VALUES('T00007','A00001',to_date('2013-03-13','YYYY-MM-


DD'),'Cash','Deposit',4000);

INSERT INTO TRAN_DETAILS VALUES('T00008','A00001',to_date('2013-03-14','YYYY-MM-


DD'),'Cheque','Deposit',3000);
Classification: Internal

INSERT INTO TRAN_DETAILS VALUES('T00009','A00001',to_date('2013-03-21','YYYY-MM-


DD'),'Cash','Withdrawal',9000);

INSERT INTO TRAN_DETAILS VALUES('T00010','A00001',to_date('2013-03-22','YYYY-MM-


DD'),'Cash','Withdrawal',2000);

INSERT INTO TRAN_DETAILS VALUES('T00011','A00002',to_date('2013-03-25','YYYY-MM-


DD'),'Cash','Withdrawal',7000);

INSERT INTO TRAN_DETAILS VALUES('T00012','A00007',to_date('2013-03-26','YYYY-MM-


DD'),'Cash','Withdrawal',2000);

--Records for loan details

INSERT INTO loan VALUES('C00001','B00001',100000);

INSERT INTO loan VALUES('C00002','B00002',200000);

INSERT INTO loan VALUES('C00009','B00008',400000);

INSERT INTO loan VALUES('C00010','B00009',500000);

INSERT INTO loan VALUES('C00001','B00003',600000);

INSERT INTO loan VALUES('C00002','B00001',600000);


Classification: Internal

Requirement 1: Update Customer Account Balance


1. Update the account_balance in Account table
2. For account type saving
3. Increase the account_balance by 500 for all the account with account type saving

QUERY:

UPDATE account

SET OPEN_BALANCE = OPEN_BALANCE + 500

WHERE AC_TYPE='Saving';

OUTPUT:
Classification: Internal

Requirement 2: Query to display customer information based on date of birth month


a. Display customer first_name and date_of_birth
b. Display date_of_birth in format of “DD-MON-YYYY”
c. Customer whose date of birth month September or November or

Expected Result:

FNAME DATE OF BIRTH


------------------------ ---------------------------
Rahul 26- SEP-1981
Parul 03- NOV-1976
Naveen 19-SEP-1976
Chitresh 06-NOV-1992
Amit 06-SEP-1981

QUERY:

SELECT FIRST_NAME AS F_NAME, CUST_DOB AS DATE_OF_BIRTH FROM customer

WHERE (

extract(MONTH FROM CUST_DOB)=extract(MONTH FROM TO_DATE('01-SEP-2022', 'DD-MON-YYYY'))

) or (

extract(MONTH FROM CUST_DOB)=extract(MONTH FROM TO_DATE('01-NOV-2022', 'DD-MON-YYYY'))

)
Classification: Internal

OUTPUT:
Classification: Internal

Requirement 3: Query to display city name and number of customer


In that city
a. Display city name and number of customer in that city
b. Display only those cities having prefix ‘p’ or ‘c’ (not a case sensitive )

Expected Result:

CITY NUMBER OF CITY

--------------- ---------------

pune 1

Chennai 1

QUERY:

SELECT CITY, COUNT(CUST_ID) AS NO_OF_CUSTOMERS FROM customer

GROUP BY CITY;

OUTPUT:
Classification: Internal

Requirement 4: Query to Display Customer name in given format along with loan amount
a. Display customer name first name , middle name ,last name as shown in expected
result
b. If middle name is not present then print ‘—’ in place of middle name

Expected Result:
CUSTOMER NAME LOAN AMOUNT
RameshChandraSharma 600000
AvinashSunderMinha 600000
AvinashSunderMinha 200000
Abhishek--Dutta 400000
Shankar--Nair 500000

QUERY:

SELECT CONCAT(CONCAT(CUSTOMER.first_name, DECODE(CUSTOMER.mid_name, NULL, '—',


CUSTOMER.mid_name)), CUSTOMER.last_name) AS CUSTOMER_NAME, LOAN.LOAN_AMOUNT

FROM loan INNER JOIN customer ON loan.cust_id=customer.cust_id;

OUTPUT:
Classification: Internal

Requirement 5: Query to Display Customer Name and the account details in given format
a. Display customer first name , type of transaction and number of transaction

Expected Result:
Name Transaction Type Number OF Transaction
Avinash Withdrawal 1
Avinash Deposit 2
Ramesh Withdrawal 3
Ramesh Deposit 3
Amit Withdrawal 1
Amit Deposit 2

QUERY:

SELECT customer.first_name as Name, tran_details.tran_type, COUNT(*) AS NO_OF_TRANSACTION


from customer
INNER JOIN account ON customer.cust_id=account.cust_id
INNER JOIN tran_details ON tran_details.ac_number=account.ac_number
GROUP BY customer.first_name, tran_details.tran_type;

OUTPUT:
Classification: Internal

Requirement 6: Query to display branch name and total number of account present in that
branch
Expected Result:
Branch Name Number Of Accounts
New Delhi main branch 2

Mandvi 2

Delhi cant 1

Mahim 1

Asaf ali road 3

Vile parle 1

QUERY:

SELECT branch.branch_name, COUNT(*) AS NO_OF_ACCOUNTS

FROM account

INNER JOIN branch ON account.branch_id=branch.branch_id

GROUP BY branch.branch_name;

OUTPUT:
Classification: Internal

Requirement 7: Query to display customer information who are having loan on their
Bank account
a. Display first name, middle name ,last name , mobile number for the customer
b. Display first name middle name and last name
c. Assign as message ‘not assigned ‘if middle name is not in database
d. Display mobile number in given format (444-656-9898)

Expected Result:
First Name Middle Name Last Name Contact number
Ramesh Chandra Sharma 954-431-9834
Avinash Sunder Minha 987-765-3210
Abhishek not assigned Dutta 985-561-9876
Shankar not assigned Nair 876-654-8907

QUERY:
SELECT customer. FIRST_NAME,
DECODE(customer.MID_NAME, NULL, 'not assigned', customer. MID_NAME) AS
MIDDLE_NAME,
customer. LAST_NAME,
SUBSTR(customer.MOBILENO, 1, 3) || '-' || SUBSTR(customer.MOBILENO, 4, 3) || '-' ||
SUBSTR(customer.MOBILENO, 7, 4) AS CONTACT_NUMBER
FROM customer
INNER JOIN loan ON customer.cust_id=loan.cust_id
GROUP BY customer. FIRST_NAME, customer. MID_NAME, customer. LAST_NAME, customer.
MOBILENO;
Classification: Internal

OUTPUT:
Classification: Internal

Requirement 8: Query to display Account information based on the given Transaction date
(Use sub-query concepts to get the results)
a. Display Account number, Account type and status customer

QUERY:
SELECT
account.ac_number AS ACCOUNT_NUMBER,
account.ac_type as ACCOUNT_TYPE,
account.ac_status as STATUS
FROM account
WHERE account.ac_number in
(SELECT tran_details.ac_number FROM tran_details);

OUTPUT:
Classification: Internal

Requirement 9: Query to display Account information along with the customer details based
on the given Transaction date
(use joins concept to get the results)
a. Display customer name, contact number, Account number, Account type and status
customer
b. Display contact number in given format (444-656-9898)

QUERY:
SELECT customer. FIRST_NAME || DECODE(customer.MID_NAME, NULL, '-', customer.
MID_NAME) || customer.LAST_NAME AS CUSTOMER_NAME,
SUBSTR(customer.MOBILENO, 1, 3) || '-' || SUBSTR(customer.MOBILENO, 4, 3) || '-' ||
SUBSTR(customer.MOBILENO, 7, 4) AS CONTACT_NUMBER,
account.ac_number AS ACCOUNT_NUMBER,
account.ac_type as ACCOUNT_TYPE,
account.ac_status as STATUS
FROM customer
INNER JOIN account ON customer.cust_id=account.cust_id
INNER JOIN tran_details ON account.ac_number=tran_details.ac_number;
Classification: Internal

OUTPUT:

You might also like