DBMS - Lab - Sankara Karthik
DBMS - Lab - Sankara Karthik
CSE201
Practical file
Submitted by:
Sankarakarthik
A2305222294
5CSE4Y
Submitted to:
Dr Subhash Chand Gupta
Experiment-1
To examine and evaluate different SQL DDL, DQL, and DML commands
● DDL queries are used to define or modify database structures, such as tables, schemas, or
indexes.
● Common DDL statements include:
○ CREATE: Used to create objects (tables, databases, etc.).
● DML queries are used for managing data within the database tables.
● Common DML statements include:
○ SELECT: Retrieves data from the database.
DQL queries are used for querying and retrieving data from the database tables. Common DQL
statements include:
CODE:
OUTPUT:
-- Drop the table (completely remove the table from the database)
DROP TABLE StudentA2305222294;
SELECT * FROM StudentA2305222294;
Experiment -2
Functions in SQL
UPPER FUNCTION
LIKE CLAUSE
● Description: Searches for a specified pattern in a column.
● Usage: Used in WHERE clauses to filter results based on patterns.
● Example: SELECT Name, Occupation
● FROM People_294
● WHERE Name LIKE 'S';
CONCAT FUNCTION
● Description: Concatenates two or more strings into one.
● Usage: Joins multiple strings into a single string.
● Example:
● SELECT Name, Occupation, CONCAT(Name, ' - ', Occupation)
AS FullDescription FROM
People_294;
LENGTH / CHAR_LENGTH
● Description: Returns the number of characters in a string.
● Usage: Determines the length of a string.
● Example: SELECT Name, LENGTH(Name) AS NameLength
● FROM People_294;
TRIM FUNCTION
● Description: Removes leading and trailing spaces from a string.
● Usage: Cleans up spaces around the text. ●
Example:
● SELECT Name, TRIM(Name) AS TrimmedName ● FROM
People_294;
COUNT
● Description: Counts the number of rows in the table. ●
FROM People_294;
SUM
FROM People_294;
AVG
● Description: Computes the average age of people.
● Example:SELECT AVG(Age) AS AverageAge
FROM People_294;
MIN
● Description: Returns the smallest age in the table.
● Example:SELECT MIN(Age) AS YoungestAge
FROM People_294;
MAX
● Description: Returns the largest age in the table.
● Example:SELECT MAX(Age)
Keys are one of the most important elements in a relational database to maintain the
relationship between the tables and it also helps in uniquely identifying the data from a table.
Primary Key
A primary key is a column (or a combination of columns) in a database table that uniquely
identifies each row in that table. Primary keys must contain unique values and cannot contain
NULL values. Each table can have only one primary key.
Example
Output
Foreign Key
A foreign key is a column (or a combination of columns) in one table that refers to the
primary key in another table. Foreign keys establish a relationship between two tables and
help maintain referential integrity.
• Referential Integrity: A foreign key value must match a primary key value in another
table or be NULL.
• Relationship: They define how data in one table relates to data in another.
Example
Output
All Tables that used in Experiment 4,5,6
Experiment-4
Client product subqueries
Output:
b. Finding the name and complete address for the customer who has placed Order
number 'O19001'.
Output:
c. Finding the clients who have placed orders before the month of May'02.
Output:
d. Find out if the product 'Lycra Tops' has been ordered by any client and print the
ClientNo, Name to whom it was sold.
Output:
e. Find the names of clients who have placed orders worth Rs. 10000 or more.
Output:
Experiment-5
Client product group by
Printing the description and total quantity sold for each product.
Output:
Output:
c. Calculating the average quantity sold for each client that has a maximum
order value of 15000.00.
Output:
d. Finding out the total of all the billed orders for the month of June.
Output:
Experiment-6
Client Product join
a. Find out the products, which have been sold to 'Ivan Bayross'.
Output:
b. Finding out the products and their quantities that will have to be delivered in
the current month.
Output:
c. Listing the ProductNo and description of constantly sold (i.e. rapidly moving)
products.
Output:
Output:
e. Listing the products and orders from customers who have ordered less than 5
units of 'Pull Overs'.
Output:
f. Finding the products and their quantities for the orders placed by 'Ivan Bayross'
and 'Mamta Muzumdar'.
Output:
g. Finding the products and their quantities for the orders placed by ClientNo
'C00001' and 'C00002'.
Output:
Experiment-7
Given a relational database, create expressions in QBE for each of the SQL queries.
Required Tables
Employee
Works
Company
Manages
Updated table
ii. Give all employees of First Bank Corporation a 10% raise.
Updated table
Updated table
iv. Give all mangers in the database a 10% raise unless the salary would be greater
than Rs.100,000. In such a case give only a 3% raise.
Updated table
Experiment 8
Construct the SQL queries for the given relational database
Required Tables
Patients
Doctors
Visits
Output:
ii. Who are the surgeons?
Output:
Output:
Output:
Experiment 9
Assignment 4
1. Create a database called COMPANY consisting of two tables - EMP & DEPT
EMP
DEPT
2. Perform the following queries on the tables just created:
Output;
2. List details of employees who have joined before 30 Sep 81.
Output:
Output:
4. List the names of employees whose employee numbers are 7369, 7521, 7839,
7934, 7788.
Output:
Output:
6. List employee names for those who have joined between 30 June and 31 Dec. ‘81.
Output:
7. List the different designations in the company.
Output:
8. List the names of employees who are not eligible for commission.
Output:
9. List the name and designation of the employee who does not report to anybody.
Output:
10. List the employees not assigned to any department.
Output:
Output:
12. List employees hose names either start or end with “S”.
Output:
13. List names of employees whose names have “i” as the second character.
Output:
14. List the number of employees working with the company.
Output:
Output:
Output:
17. List the maximum, minimum and average salary in the company.
Output:
Output:
Experiment 10
Company Assignment
Employee Company
Works
Manages
a. Find the names, street address, and cities of residence for all employees who work for
'First Bank Corporation' and earn more than $10,000.
Output
b. Find the names of all employees in the database who live in the same cities as the
companies for which they work.
Output
c. Find the average salary company wise and display it with the heading “Average
Salary”.
Output
d. Find the names of all employees in the database who live in the same cities and on
the same streets as do their managers.
Output
e. Find the names of all employees in the database who do not work for 'First Bank
Corporation‘
Output
f. Find the names of all employees in the database who earn more than every employee
of 'Small Bank Corporation'. Assume that all people work for at most one company.
Output
g. Find the names, street address, and cities of residence for all employees who work for
'First Bank Corporation' and earn more than $10,000 and less than $20,000.
Output
h. Find the names of all employees in the database who live in the same cities as the
companies for which they work.
Output
i. Find the names of all employees in the database who earn more than every employee
of 'Small Bank Corporation'. Assume that all people work for at most one company.
Output