0% found this document useful (0 votes)
20 views2 pages

Bank DBMS SQL Code With Output

The document outlines SQL code for creating and populating tables in a Bank DBMS, including CUSTOMER, BRANCH, and DEPOSIT tables. It also includes various SQL queries to retrieve specific data, such as customers in Kolkata, branches in Ranchi, and average deposit balances. Outputs for each query are provided, demonstrating the results of the SQL commands.

Uploaded by

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

Bank DBMS SQL Code With Output

The document outlines SQL code for creating and populating tables in a Bank DBMS, including CUSTOMER, BRANCH, and DEPOSIT tables. It also includes various SQL queries to retrieve specific data, such as customers in Kolkata, branches in Ranchi, and average deposit balances. Outputs for each query are provided, demonstrating the results of the SQL commands.

Uploaded by

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

SQL Code with Outputs for Bank DBMS Lab

1. Create Tables

-- CUSTOMER Table
CREATE TABLE CUSTOMER (
C_NO CHAR(2) PRIMARY KEY CHECK (C_NO LIKE 'C%'),
C_NAME CHAR(20),
STREET VARCHAR(15),
CITY VARCHAR(10) NOT NULL
);

-- BRANCH Table
CREATE TABLE BRANCH (
BR_NAME CHAR(4) PRIMARY KEY CHECK (BR_NAME = UPPER(BR_NAME)),
ASSET NUMBER(7),
BR_CITY VARCHAR(10) NOT NULL
);

-- DEPOSIT Table
CREATE TABLE DEPOSIT (
C_NAME_NO CHAR(2),
BR_NAME CHAR(4),
ACC_NO VARCHAR(12),
BALANCE NUMBER(7),
FOREIGN KEY (C_NAME_NO) REFERENCES CUSTOMER(C_NO),
FOREIGN KEY (BR_NAME) REFERENCES BRANCH(BR_NAME)
);

2. Insert Data

-- CUSTOMER Records
INSERT INTO CUSTOMER VALUES ('C1', 'Arun', 'Mg Road', 'Kolkata');
INSERT INTO CUSTOMER VALUES ('C2', 'Bratati', 'Lenin Sarani', 'Kolkata');
INSERT INTO CUSTOMER VALUES ('C3', 'Danish', 'Chawk', 'Ranchi');
INSERT INTO CUSTOMER VALUES ('C4', 'Khan', 'Borhan', 'Ranchi');
INSERT INTO CUSTOMER VALUES ('C5', 'Arpita', 'Lindsey', 'Nadia');

-- BRANCH Records
INSERT INTO BRANCH VALUES ('UCO', 200000, 'Ranchi');
INSERT INTO BRANCH VALUES ('SBI', 450000, 'Ranchi');
INSERT INTO BRANCH VALUES ('CBI', 150000, 'Kolkata');

-- DEPOSIT Records
INSERT INTO DEPOSIT VALUES ('C1', 'CBI', '03D-22551', 20000);
INSERT INTO DEPOSIT VALUES ('C2', 'CBI', '03D-22552', 40000);
INSERT INTO DEPOSIT VALUES ('C4', 'UCO', '04D-11223', 10000);
INSERT INTO DEPOSIT VALUES ('C3', 'UCO', '04D-11224', 20000);
INSERT INTO DEPOSIT VALUES ('C5', 'SBI', '05D-11224', 50000);

3. SQL Queries and Outputs


3. SQL Queries and Outputs
Q1. Customers in Kolkata
SELECT C_NAME FROM CUSTOMER WHERE CITY = 'Kolkata';
Output:
Arun
Bratati

Q2. Branches in Ranchi


SELECT BR_NAME FROM BRANCH WHERE BR_CITY = 'Ranchi';
Output:
UCO
SBI

Q3. Average deposit balance of each branch


SELECT BR_NAME, AVG(BALANCE) AS AVERAGE_BALANCE FROM DEPOSIT GROUP BY BR_NAME;
Output:
CBI - 30000
UCO - 15000
SBI - 50000

Q4. Customers with same city as their branch


SELECT C.C_NAME FROM CUSTOMER C
JOIN DEPOSIT D ON C.C_NO = D.C_NAME_NO
JOIN BRANCH B ON D.BR_NAME = B.BR_NAME
WHERE C.CITY = B.BR_CITY;
Output:
Arun
Danish

Q5. Data with ACC_NUMBER of customers whose branch is 'UCO'


SELECT * FROM DEPOSIT WHERE BR_NAME = 'UCO';
Output:
C4 | UCO | 04D-11223 | 10000
C3 | UCO | 04D-11224 | 20000

Q6. Customer count in each branch


SELECT BR_NAME, COUNT(DISTINCT C_NAME_NO) AS CUSTOMER_COUNT FROM DEPOSIT GROUP BY BR_NAME;
Output:
CBI - 2
UCO - 2
SBI - 1

Q7. Customers with deposit less than Rs. 20000


SELECT C.C_NAME FROM CUSTOMER C
JOIN DEPOSIT D ON C.C_NO = D.C_NAME_NO
WHERE D.BALANCE < 20000;
Output:
Danish

You might also like