RDBMS LAB MANUAL w3
RDBMS LAB MANUAL w3
CCS 1
JSS SCIENCE AND TECHNOLOGY UNIVERSITY
DEPARTMENT OF COMPUTER APPLICATIONS
DBMS Languages
A DBMS supports various languages to interact with the database. The main types of DBMS languages
are:
1. Data Definition Language (DDL):
o Purpose: Defines the structure of the database, including creating, altering, and deleting
tables, schemas, and other database objects.
o Common Commands:
▪ CREATE: Defines a new table or database object.
▪ ALTER: Modifies an existing database object.
▪ DROP: Deletes a database object.
▪ TRUNCATE: Removes all records from a table, retaining the table structure.
2. Data Manipulation Language (DML):
o Purpose: Manages and manipulates data in the database (insert, update, delete,
retrieve).
o Common Commands:
▪ INSERT: Adds new data into a table.
▪ UPDATE: Modifies existing data in a table.
▪ DELETE: Removes data from a table.
▪ SELECT: Retrieves data from a table.
3. Data Control Language (DCL):
o Purpose: Controls access to the database and manages permissions.
o Common Commands:
CCS 2
JSS SCIENCE AND TECHNOLOGY UNIVERSITY
DEPARTMENT OF COMPUTER APPLICATIONS
o UPDATE:
UPDATE Students SET Age = 23 WHERE StudentID = 1;
o DELETE:
DELETE FROM Students WHERE Age < 18;
3. Data Control Language (DCL):
o GRANT:
GRANT SELECT, INSERT ON Students TO UserName;
o REVOKE:
REVOKE SELECT ON Students FROM UserName;
4. Transaction Control Language (TCL):
o COMMIT:
COMMIT;
o ROLLBACK:
ROLLBACK;
CCS 4
JSS SCIENCE AND TECHNOLOGY UNIVERSITY
DEPARTMENT OF COMPUTER APPLICATIONS
Banking Database
Week-2
This lab focuses on creating a database schema for a Banking Database and performing operations
using SQL. The database schema includes six tables: BRANCH, ACCOUNT, CUSTOMER,
DEPOSITOR, LOAN, and BORROWER.
Objectives
1. Learn to create relational database tables with primary and foreign keys.
1. Creating Tables
a. BRANCH Table
city VARCHAR(50),
asset VARCHAR(50)
);
b. ACCOUNT Table
branch_name VARCHAR(50),
balance FLOAT,
CCS 5
JSS SCIENCE AND TECHNOLOGY UNIVERSITY
DEPARTMENT OF COMPUTER APPLICATIONS
);
c. CUSTOMER Table
street VARCHAR(100),
city VARCHAR(50)
);
d. DEPOSITOR Table
customer_name VARCHAR(50),
account_number VARCHAR(50),
);
• Foreign Keys:
e. LOAN Table
CCS 6
JSS SCIENCE AND TECHNOLOGY UNIVERSITY
DEPARTMENT OF COMPUTER APPLICATIONS
branch_name VARCHAR(50),
amount INTEGER,
);
f. BORROWER Table
customer_name VARCHAR(50),
loan_number VARCHAR(50),
);
• Foreign Keys:
2. Inserting Data
CCS 7
JSS SCIENCE AND TECHNOLOGY UNIVERSITY
DEPARTMENT OF COMPUTER APPLICATIONS
('Bob', 'ACC002');
('Bob', 'LN002');
3. Selecting Data
CCS 8
JSS SCIENCE AND TECHNOLOGY UNIVERSITY
DEPARTMENT OF COMPUTER APPLICATIONS
FROM CUSTOMER c
Primary Keys:
• BRANCH(branch_name)
• ACCOUNT(account_number)
• CUSTOMER(customer_name)
• LOAN(loan_number)
Foreign Keys:
• ACCOUNT(branch_name) → BRANCH(branch_name)
• DEPOSITOR(customer_name) → CUSTOMER(customer_name)
• DEPOSITOR(account_number) → ACCOUNT(account_number)
• LOAN(branch_name) → BRANCH(branch_name)
• BORROWER(customer_name) → CUSTOMER(customer_name)
• BORROWER(loan_number) → LOAN(loan_number)
CCS 9
JSS SCIENCE AND TECHNOLOGY UNIVERSITY
DEPARTMENT OF COMPUTER APPLICATIONS
Week-3
Let's continue from the Banking Database and generate the SQL queries for the additional tasks. We
will focus on specific queries involving aggregate functions, comparison operators, and logical
operators. Below are the SQL queries for the required tasks.
1. List the loan number from LOAN having amount 10000 with a specific branch name.
For this query, we will filter the LOAN table for rows where the amount is 10000 and the branch_name
matches a specific branch.
SELECT loan_number
FROM LOAN
2. List the loan number with an amount between 1000 and 10000.
This query uses the BETWEEN operator to filter the LOAN table for loans where the amount is
between 1000 and 10000.
SELECT loan_number
FROM LOAN
If we want to filter customer names containing a specific substring (e.g., names containing "Ali"), we
can use the LIKE operator with wildcard characters (%).
SELECT customer_name
FROM CUSTOMER
To get the count of records (tuples) in the CUSTOMER table, we use the COUNT() aggregate function.
FROM CUSTOMER;
CCS 10
JSS SCIENCE AND TECHNOLOGY UNIVERSITY
DEPARTMENT OF COMPUTER APPLICATIONS
5. List customer name, loan number, and amount with a specific branch name.
This query involves joining the BORROWER, LOAN, and CUSTOMER tables to list the customer
name, loan number, and loan amount for a specific branch.
FROM BORROWER b
The SUM() aggregate function is used to calculate the total sum of all loan amounts.
FROM LOAN;
The AVG() function calculates the average balance from the ACCOUNT table.
FROM ACCOUNT;
FROM LOAN;
FROM ACCOUNT;
FROM LOAN;
Here we use the > operator to find accounts with a balance greater than 5000.
FROM CUSTOMER c
We use the > comparison operator to find loan amounts greater than 5000.
FROM BORROWER b
Using the <= operator, this query retrieves accounts with a balance less than or equal to 1000.
FROM ACCOUNT a
d. Find customers with loans less than 5000 and belonging to a specific branch:
FROM BORROWER b
CCS 12
JSS SCIENCE AND TECHNOLOGY UNIVERSITY
DEPARTMENT OF COMPUTER APPLICATIONS
a. Find customers who have a balance greater than 1000 and have a loan of more than 5000:
This query uses AND to combine the two conditions: balance greater than 1000 and loan amount
greater than 5000.
FROM CUSTOMER c
b. Find customers who either have a loan or an account with a balance greater than 5000:
This query uses the OR operator to find customers who meet at least one of the conditions.
SELECT c.customer_name
FROM CUSTOMER c
c. Find customers with a loan amount between 1000 and 5000, and from a specific branch:
Here, we combine AND and BETWEEN to find customers who have a loan between 1000 and 5000
and are from a specific branch.
CCS 13
JSS SCIENCE AND TECHNOLOGY UNIVERSITY
DEPARTMENT OF COMPUTER APPLICATIONS
FROM BORROWER b
d. Find customers with names starting with "A" and having an account balance greater than
2000:
This query uses both LIKE and the AND logical operator.
FROM CUSTOMER c
• List loan numbers based on conditions: Using WHERE, BETWEEN, and comparison
operators.
• Substring search: Using the LIKE operator with %.
• Count tuples: Using COUNT() aggregate function.
• Join tables for specific information: Using JOIN to combine data from multiple tables.
• Aggregate functions: Using SUM(), AVG(), MAX(), MIN(), and COUNT() for calculations.
• Comparison operators: Using =, <, >, <=, >=, and BETWEEN to filter data.
• Logical operators: Using AND, OR, and NOT to combine multiple conditions.
These queries address the tasks for retrieving data from the Banking Database, including using
aggregate functions, comparison operators, and logical operators.
CCS 14