Professional Documents
Culture Documents
1. Develop a stored procedure in SQL to retrieve the number of students who have scored
above a certain GPA threshold in each grade level. The stored procedure should take two
parameters: the GPA threshold and the grade level. It should return the count of students
meeting the criteria.
2. Compare cursor and trigger.
3. How can you execute a stored procedure in SQL, and what are the different ways to pass
parameters to it?
4. Suppose you have a database containing information about employees in a company,
including their ID, name, department, and salary. Create a view that displays the name
and salary of all employees who earn more than $50,000 per year and work in the
Marketing or Sales department.
5. Construct the code to declare cursor to fetch one student detail.
6. Relate primary storage media with secondary storage media.
7. Create an example to show how the transaction log is used for recovery in a database
system.
8. List the phases of two-phase locking protocol.
9. Build a scenario where concurrency control mechanisms are necessary in a database
system.
10. Mention any four hashing methods.
11. Create a view in SQL that displays the name, department, and salary of all employees who
earn more than $60,000 per year and work in the Engineering or Research department.
12. Show how to enable or disable a trigger in SQL.
13. Suppose you have a table called "Students" that contains information about students in a
school, including their ID, name, and grade level.
Prepare a stored procedure that takes a grade level as input and returns the average GPA
of all students in that grade level.
14. Can you execute CRUD operations (Create, Read, Update, Delete) on a database view?
Justify your answer.
15. Build the syntax of creating a cursor in SQL.
16. Contrast embedded SQL and dynamic SQL.
17. Develop a scenario to show where undo and redo operations in log-based recovery is
necessary.
18. Differentiate strict two-phase locking protocol and rigorous two-phase locking protocol.
19. Construct an example stating the isolation property of transactions.
20. List the ACID properties of a transaction.
PART B
1.From the following tables, create a view 'nameorders' to get the salesperson and customer
by name. Return order name, purchase amount, salesperson ID, name, customer name only
for the customer whose salesman_id's and customer_id's are same.
Sample Table: salesman
Sample Table: orders
2. From the following table, create a view 'salesown' for all salespersons. Return salesperson
ID, name, and city.
Sample table: salesman
3. From the following table, create a view 'totalforday' to count the number of unique
customers, compute the average and total purchase amount of customer orders by each date.
Round off the average and sum values to 2 decimal places using round() and Give an alias
name to Average as AVG and for the sum as SUM.
Sample table: orders
5. Using the Cursor concept, Create a stored procedure (Gettotalcredit) that creates the
student list with all the required details.
Fetch each row using the cursor and get the required details.
Procedure Name: Gettotalcredit (INOUT full_studentList varchar(4000))
Table Name: Student
Please find the column names and data type below.
sid varchar(2) primary key,
name varchar(30),
total_credit int,
dept_name varchar(30)
For each student: student id, student Name, total credit, and class should be displayed
separated by a comma
Each student's details should end with a semicolon ;
Sample Output:
S1,Alice,8,First Class;S2,Dave,7,First Class;S3,Charlie,6,First Class;
The class should be derived as follows:
If total credit is less than or equal to 5, then it is "Second Class"
If total credit is greater than 5, then it is "First Class"
Note: Table names are case sensitive
Use proper delimiter to define the procedure. At the end of the procedure, reset the
delimiter to ;
6. Using the Cursor concept, Create a stored procedure (createEmailList) that creates an
email list of all employees in the employees table.
Each email id should end with a semicolon (;) symbol
Procedure Name: createEmailList(INOUT emailList varchar(4000))
Table Name: employees
Please find the column names and data type below.
employeeNumber int(11) primary key NOT NULL
lastName varchar(50) NOT NULL
firstName varchar(50) NOT NULL
extension varchar(10) NOT NULL
email varchar(100) NOT NULL
officeCode varchar(10) NOT NULL
reportsTo int(11) DEFAULT NULL
jobTitle varchar(50) NOT NULL
Note: Table names are case sensitive
Use proper delimiter to define the procedure. At the end of the procedure, reset the
delimiter to ;
7. Given the Employees table, Create a Cursor to increment the salary based on the
designation. Update the Employee Salary based on the given condition. As Cursor can be
implemented inside Stored Procedure, Create a procedure
Procedure Name: Employee_Updated_Salary()
SALARY UPDATE
For the Manager, the salary should be incremented by 5000.
For Developer, the salary should be incremented by 7000.
For Trainer, the salary should be incremented by 10000.
Table Name: Employees
EMPLOYEE_ID INT PRIMARY KEY,
EMP_NAME VARCHAR(100),
EMAIL VARCHAR(30),
PHONE_NUMBER VARCHAR(20),
HIRE_DATE DATE,
DESIGNATION VARCHAR(30),
EMP_SALARY INTEGER,
MANAGER_ID INT,
DEPARTMENT_ID INT
Note:
Table names are case sensitive
Use proper delimiter to define procedure. At the end of procedure, reset the delimiter to ;
8. Given Product table, Implement a Cursor inside Stored Procedure to count how many
products(product_name) of each product type exists with product type passed as a input
argument to the procedure.
As Cursor can be implemented inside Stored Procedure, Create a procedure
Procedure Name: ProductCount(IN product_name VARCHAR(30))
Product type should be passed as an argument.
Table Name: Product
product_id int
product_type varchar(30)
product_name varchar(30)
Count will be displayed with header name ProductCount
Sample Output:
ProductCount
10
Note: Table names are case sensitive
Use proper delimiter to define procedure. At the end of procedure, reset the delimiter to ;
9. Create an after insert trigger named sales_details_insert, whenever any inserts happens on
the table sales_details, the table total_sales should either insert or update the total sales for
every department to maintain the total number of products sold per department.
Here, we are creating AFTER INSERT trigger named sales_details_insert on table
sales_details.
If the insert happens on the table sales_details for the first time, a row gets inserted in the
total_sales table.
When there are successive inserts in sales_details for the same department, the total_sales
table will update by adding the NEW no_products_sold to maintain the total sale for a
particular department.
Below are the department names we need to consider (sales_department column)
Dairy
Groceries
Medicines
Table Details (Table names are case sensitive)
10. Create a trigger named product_availability that inserts mapping records into the
products_to_stores table.
This trigger is used to enforce business logic; in particular, it helps define the product
availability for the different stores.
When an item is being inserted into the products table, the trigger will check the availability
field.
If availability column is marked with the LOCAL value, the product will be made available
in one store only.
(We need to insert a new row in products_to_stores table with the new product id and
store_id as 1.)
Example:
INSERT INTO products_to_stores (product_id, store_id) VALUES (new product id, 1);
Any other value will instruct the trigger to make the product available to the two stores that
we created earlier.
(We need to insert 2 new rows in products_to_stores table with the new product id and
store_id as 1 as one row and new product id and store_id 2 as second row )
Example:
INSERT INTO products_to_stores (product_id, store_id) VALUES (new product id, 1);
INSERT INTO products_to_stores (product_id, store_id) VALUES (new product id, 2);
Stores
----------
Store_id(PK) BIGINT Auto Increment
Store_name VARCHAR(35)
Products
-------------
Product_id(PK) BIGINT Auto Increment
Product_name VARCHAR(50)
Cost_price DOUBLE
Retail_price DOUBLE
Availability VARCHAR(5)
Products_to_stores
-------------------------
ref_id (PK) BIGINT Auto Increment
product_id BIGINT
store_id BIGINT
Note:
Use proper delimiters before defining the trigger
Note:
Use proper delimiters before defining the trigger
14. Given the schema of Railway Reservation System, write a query to list the senior
citizen passenger details.
Sort the output by ascending order of passenger names.
Note:
Refer the table Passenger from the given schema.
Age of senior citizen should be greater than or equal to 60.
Table names are case sensitive.
15. Given the schema of a Bank Management system. Write a query to display the number
of customers from Delhi. Give the count an alias name of Cust_Count.
The output prints the total number of customers from Delhi.
16.Given the schema of a Bank Management system, Write a query to display the custid,
fname and customer's dob. Display in sorted order of date of birth year and within that sort
by firstname.
The output prints the custid, fname and customer's dob in sorted order of date of birth year
and within that in the sorted order of firstname.
17. Discuss in detail the purpose of indexing and how it can be done by using B+ tree.
20. Construct a B+ tree for the following set of search key values. (Amala,
Dolly, Bala, Sona, Chinna, Ezhil, Falley, Gilda,). Assume the number of
pointers in each node as 4. Also do the following Operations Sequentially to the tree that
have constructed.
Insert “Amutha”, Insert “Raja”, Insert “Vickram”, Delete “Sona” and
Delete “Gilda”.