0% found this document useful (0 votes)
5 views4 pages

Stored Procedures Lab Exercises

Uploaded by

Heckin Good
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)
5 views4 pages

Stored Procedures Lab Exercises

Uploaded by

Heckin Good
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

NAME: ASGHAR QAMBER RIZVI BSCS 4A ENROLLMENT : 02-134222-061

Lab10: Stored Procedures

Objectives:
To learn the Stored Procedures

Exercises

Using StudentInfotmation database, formulate the following queries:


1. Create a stored procedure DISPLAY without parameters. The procedure must display
Teacher ID, Teacher Name and BasicSalary of all the Faculty that are permanent.

2. Create a stored procedure DISPLAY2 with parameters. It must take Status as an input and
must return the Count of Employee related to the status and Total Salary of the input Status.

Department of Computer Sciences 1/4 Semester: Spring 2024


CSL-220: Database Management Systems Lab Lab10: Stored Procedures
NAME: ASGHAR QAMBER RIZVI BSCS 4A ENROLLMENT : 02-134222-061

3. Create a stored procedure DISPLAY3 with parameters. It must take Semester as an input
and must return the Student Name, Lowest and Highest Marks of final exam of the inputted
Semester.

Department of Computer Sciences 2/4 Semester: Spring 2024


CSL-220: Database Management Systems Lab Lab10: Stored Procedures
NAME: ASGHAR QAMBER RIZVI BSCS 4A ENROLLMENT : 02-134222-061

4. Create a Stored procedure DISPLAY4 that displays the information of all the subjects that
are being taught by the teachers whose Job is ‘Sr. Lecturer’.

Department of Computer Sciences 3/4 Semester: Spring 2024


CSL-220: Database Management Systems Lab Lab10: Stored Procedures
NAME: ASGHAR QAMBER RIZVI BSCS 4A ENROLLMENT : 02-134222-061

5. Create a stored procedure that will display the information of all the courses that are taught
in second semester and are of credit hours 3+1.

Department of Computer Sciences 4/4 Semester: Spring 2024


CSL-220: Database Management Systems Lab Lab10: Stored Procedures

Common questions

Powered by AI

Stored procedures in a database management system, such as those described in the exercises, allow for encapsulating complex operations within a database, improving performance by reducing network traffic, and enhancing security by restricting direct access to data. In the context of the presented exercises, stored procedures are used for tasks like displaying teacher and student information based on specific criteria, which helps in executing recurrent tasks with efficiency and consistency. For instance, DISPLAY procedures can be reused and modified without extensive changes to the database structure .

Stored procedures enhance security within a database management system by limiting direct access to the underlying tables and allowing users to perform specific operations without having the ability to manipulate data directly. They encapsulate business logic while denying unauthorized users from issuing arbitrary SQL commands. In the exercises, this controlled access ensures that only predefined queries, such as those for displaying employee or student information, are executed, thus minimizing the risk of SQL injection and data breaches .

The DISPLAY4 procedure requires a query that selects and displays subject information where the teacher's job title is 'Sr. Lecturer'. The logical steps involve: 1) Joining tables (if necessary) to associate subjects with their respective teachers, 2) Filtering records to only include those with the job title 'Sr. Lecturer', and 3) Selecting the relevant columns to display subject information. This may involve ensuring indexes are used for quick access to teacher records .

Incorporating multiple stored procedures, as demonstrated, can significantly optimize database performance by reducing network overhead and centralizing operations. This approach allows operations to execute within the database server, minimizing the latency of data transfer between application and server. Precompiled procedures eliminate the need for repeated query parsing and planning. However, if not properly managed, the complexity and maintenance overhead of numerous procedures could lead to difficulty in debugging and updating, potentially affecting performance negatively if procedures aren't optimized for execution efficiency .

A basic structure for a stored procedure that takes 'Semester' as an input might involve the following SQL clauses: DELIMITER // CREATE PROCEDURE DISPLAY3(IN inputSemester CHAR(10)) BEGIN SELECT StudentName, MIN(FinalExamScore) AS LowestScore, MAX(FinalExamScore) AS HighestScore FROM StudentResults WHERE Semester = inputSemester GROUP BY StudentName; END // DELIMITER ; This structure includes the INSERT clause for defining the stored procedure, SELECT for querying the data, WHERE for filtering by semester, and GROUP BY for organizing student results with aggregate functions to determine lowest and highest scores .

Some challenges in implementing the DISPLAY3 procedure include ensuring that the inputted semester is valid and exists in the database, handling semesters with no student information, and optimizing the query to efficiently retrieve student names and scores without redundancy or performance issues. Additionally, care must be taken to sort and filter data correctly to provide the lowest and highest exam scores, possibly requiring JOIN operations if student information and scores are stored in separate tables .

A stored procedure for counting employees based on their status and calculating their total salaries would involve taking 'Status' as an input parameter. It would execute a SQL query to filter employees where their status matches the input, use an aggregate function like COUNT() to tally the employees, and SUM() to compute the total salaries. This could look like: CREATE PROCEDURE DISPLAY2(IN inputStatus VARCHAR(20)) BEGIN SELECT COUNT(*), SUM(Salary) FROM Employees WHERE Status = inputStatus; END .

It is important for the DISPLAY procedure to have no parameters when displaying permanent faculty details to ensure simplicity and universality of the procedure. By removing parameters, the procedure can be used to retrieve comprehensive data for all permanent faculty without additional inputs, facilitating ease of access and reducing the complexities like validating input values or handling different scenarios that arise from having parameters .

The educational value of creating and using stored procedures through exercises like these lies in developing a deep understanding of data manipulation within database systems. They help students master key concepts such as encapsulation, data integrity, and transaction management. Moreover, these exercises enhance problem-solving skills by challenging students to architect queries that efficiently and correctly solve specified tasks. Students also gain insights into performance optimization and security considerations intrinsic to effective database management, providing applicable skills for real-world data management scenarios .

Creating a stored procedure to display information about courses taught in the second semester and with specific credit hours streamlines the retrieval of course data, making it easy to monitor and report on course offerings with precise criteria. This is particularly useful for academic planning and ensuring compliance with curriculum requirements. The procedure encapsulates this logic in a reusable and maintainable format, which reduces redundancy and simplifies workflows within database operations .

You might also like