You are on page 1of 28

CYCLE SHEET -1

DATABASE MANAGEMENT SYSTEM


SHIVANGI SINGH
21BIT0737
SQL Codes Used:
-- Bank Master table
CREATE TABLE bank_master(
code CHAR(7),
name VARCHAR(5),
doorno VARCHAR(2),
street VARCHAR(8),
landmark VARCHAR(14),
city VARCHAR(7),
state VARCHAR(10),
pincode NUMBER(6)
);
-- add primary key constraint
ALTER TABLE bank_master
ADD CONSTRAINT pk_bm_code PRIMARY key(code);

-- Customer table
CREATE TABLE customer(
cid NUMBER GENERATED ALWAYS as IDENTITY(START with 1 INCREMENT by 1),
aadharno NUMBER(12) NOT NULL,
name VARCHAR(12),
doorno VARCHAR(2),
street VARCHAR(8),
landmark VARCHAR(15),
city VARCHAR(7),
state VARCHAR(10),
pincode NUMBER(6),
dob DATE,
anyremarks VARCHAR(10)
);
-- add primary key constraint
ALTER TABLE customer
ADD CONSTRAINT pk_c_cid PRIMARY key(cid);

-- Account table
CREATE TABLE account(
aid NUMBER(3),
type VARCHAR(10),
balance NUMBER(8, 2),
bank_code CHAR(7),
cid NUMBER
);
-- add primary key constraint
ALTER TABLE account
ADD CONSTRAINT pk_a_aid PRIMARY KEY(aid);
-- add foreign key bank_code
ALTER TABLE account
ADD CONSTRAINT fk_a_bank_code
FOREIGN KEY(bank_code) REFERENCES bank_master(code);
-- add foreign key cid
ALTER TABLE account
ADD CONSTRAINT fk_a_cid
FOREIGN KEY(cid) REFERENCES customer(cid);

-- Loan table
CREATE TABLE loan(
lno NUMBER(3),
type VARCHAR(9),
amount_sanctioned NUMBER(8, 2),
balance NUMBER(8, 2),
bank_code CHAR(7),
cid NUMBER
);
-- add primary key constraint
ALTER TABLE loan
ADD CONSTRAINT pk_l_lno PRIMARY KEY(lno);
-- add foreign key bank_code
ALTER TABLE loan
ADD CONSTRAINT fk_l_bank_code
FOREIGN KEY(bank_code) REFERENCES bank_master(code);
-- add foreign key cid
ALTER TABLE loan
ADD CONSTRAINT fk_l_cid
FOREIGN KEY(cid) REFERENCES customer(cid);
-- add value constraint on type
ALTER TABLE loan
ADD CONSTRAINT ck_l_type
CHECK(type IN ('vehicle','house','education','personal'));

-- Online Deposists Table


CREATE TABLE online_deposits(
refno NUMBER(3),
type VARCHAR(3),
startdate DATE,
period NUMBER(5, 2),
cid NUMBER,
int_percen NUMBER(6, 3),
bank_code CHAR(7)
);
-- add primary key constraint
ALTER TABLE online_deposits
ADD CONSTRAINT pk_od_refno PRIMARY KEY(refno);
-- add foreign key bank_code
ALTER TABLE online_deposits
ADD CONSTRAINT fk_od_bank_code
FOREIGN KEY(bank_code) REFERENCES bank_master(code);
-- add foreign key cid
ALTER TABLE online_deposits
ADD CONSTRAINT fk_od_cid
FOREIGN KEY(cid) REFERENCES customer(cid);
-- add val constraint on type
ALTER TABLE online_deposits
ADD CONSTRAINT ck_od_type
CHECK(type IN ('RD', 'VRD', 'PPF','FD'));

-- Transactions Within Bank Table


CREATE TABLE transactions_withinbank(
tid NUMBER(3),
type CHAR(1),
id NUMBER(3),
amount NUMBER(6, 2),
date_time TIMESTAMP(6),
status VARCHAR(8)
);
-- add primary key constraint
ALTER TABLE transactions_withinbank
ADD CONSTRAINT pk_tw_tid PRIMARY KEY(tid);
-- add value constraint for status
ALTER TABLE transactions_withinbank
ADD CONSTRAINT ck_tw_status
CHECK (status IN ('declined', 'failed', 'success'));

Output SS:
Inserting Values in all Tables:

Codes Used:

-- Insert values in table


-- bank_master
INSERT INTO bank_master
VALUES(
'&code',
'&name',
'&doorno',
'&street',
'&landmark',
'&city',
'&state',
'&pincode'
);
-- customer
INSERT INTO customer(
aadharno,
name,
doorno,
street,
landmark,
city,
state,
pincode,
dob,
anyremarks
) VALUES(
'&aadharno',
'&name',
'&doorno',
'&street',
'&landmark',
'&city',
'&state',
'&pincode',
'&dob',
'&anyremarks'
);
-- account
INSERT INTO account
VALUES(
'&aid',
'&type',
'&balance',
'&bank_code',
'&cid',
);
-- loan
INSERT INTO loan
VALUES(
'&lno',
'&type',
'&amount_sanctioned',
'&bank_code',
'&cid'
);
-- online_deposits
INSERT INTO online_deposits
VALUES(
'&refno',
'&type',
'&startdate',
'&period',
'&cid',
'&int_person',
'&bank_code'
);
-- transactions_within
INSERT INTO transactions_within
VALUES(
'&tid',
'&type',
'&id',
'&amount',
'&date_time',
'&status'
);

Screenshots:
Tables After Populating it with data:

Bank_master

Customer
Account:
Loan

Online_Desposits

Transactions_withinbank
1. Remove All the rows from the Loan Table permanently
Code:
TRUNCATE TABLE loan;
Output:

2. Change the name of the loan table to Loan_Details


Code:

ALTER TABLE loan


RENAME TO loan_details;
Output:

3. List All customer details


Code:

SELECT * FROM customer;


Output:
4. List all account details of a particular customer
Code:

SELECT * FROM account


WHERE cid=1;
Output:
5. Give a list of Customers in ascending order of Aadhar Number.
Code:

SELECT * FROM customer


ORDER BY aadharno;
Output:
6. List account details of particular bank (like SBI).
Code:
SELECT * FROM bank_master
WHERE code LIKE 'SBI%';
Output:

7. List the customer names who are senior citizen


Code:

SELECT * FROM customer


WHERE (2023 - EXTRACT(YEAR FROM CAST(dob AS DATE))) > 60;
Output:

8. List the transaction details within a range of numbers


Code:

SELECT * FROM transactions_withinbank


WHERE id BETWEEN 4 AND 6;
Output:
9. List the transactions details which is not success.
Code:

SELECT * FROM transactions_withinbank


WHERE status!='success';
Output:
10. Find the transaction type whose amount exceeds 50_000 and done during peak hours (10.00 am
to 2.00 pm).
Code:

SELECT * FROM transactions_withinbank


WHERE amount > 50000 AND
(EXTRACT(HOUR FROM date_time) BETWEEN 10 AND 14);
Output:

11. Find the transaction details where status is not known


Code:
SELECT * FROM transactions_withinbank
WHERE status=NULL;
Output:

12. Find the customers whose landmark (like ‘near VIT’ or ‘VIT’) and month of birth are same.
Code:

SELECT * FROM customer


WHERE EXTRACT(MONTH FROM dob)=9 AND landmark LIKE '%VIT%';
Output:

You might also like