Stored Procedure Activity
Stored Procedure Activity
STORED PROCEDURE
• A stored procedure is a precompiled collection of SQL statements and procedural
logic that is stored in the database and can be executed on demand.
• It's essentially a reusable and organized set of SQL commands that perform a specific
task or set of tasks.
• Stored procedures are widely used in database management systems like SQL Server,
MySQL, Oracle, etc.
ANSWERS
1. B) A collection of SQL statements and procedural logic stored on the
server.
2. C) Improved performance by reducing round trips to the server.
3. A) CREATE PROCEDURE
4. B) Retrieves a customer's details based on their ID.
5. C) They reduce the need for writing SQL queries in application code.
1. Create Sample Data: Populate the Customers, Products, and Orders tables with
sample data to simulate orders.
2. Create Stored Procedure: Create a stored procedure named ProcessNewOrder that
accepts parameters for CustomerID, ProductID, and Quantity. The stored procedure
should insert a new order into the Orders table.
3. Test the Stored Procedure: Execute the stored procedure ProcessNewOrder with
sample values to test its functionality and verify that it adds new orders correctly.
4. Additional Functionality (Optional): Modify the stored procedure to include error
handling, such as checking if the specified CustomerID and ProductID exist before
inserting the order. You can also include logic to update product quantities or
calculate order totals.
• Insert sample data into the Actors table to simulate actors in the database.
• Insert sample data into the MovieCast table to simulate movie casts.
Experiment:
• Modify the stored procedure or create additional stored procedures to retrieve
movie details based on different criteria (e.g., genre, director, release year).
Cleanup (Optional):
• Drop the MovieDB database after completing the activity to clean up the
environment.
• Insert sample data into the Members table to simulate library members.
• Insert sample data into the BookLoans table to simulate book loans.