Stored Procedures Questions
1. Create a stored procedure to fetch all products from a specific
category.
- Use the parameter to filter products based on the category_id.
2. Write a stored procedure to retrieve customer details by city.
- Parameters: City
- Return customers who live in the specified city.
3. Develop a stored procedure to fetch all orders for a specific store.
- Parameters: StoreId
- Return details of all orders placed at the specified store.
4. Create a stored procedure to update the quantity of a product in a
store's stock.
- Parameters: StoreId , ProductId , NewQuantity
5. Write a stored procedure to calculate the total value of items in
an order.
- Parameters: OrderId
- Use a variable to calculate the sum of (list_price * quantity) for
the specified order.
6. Create a stored procedure to insert a new product into the
production.products table.
- Parameters: ProductName , BrandId , CategoryId , ModelYear ,
ListPrice
7. Write a stored procedure to retrieve sales staff details who work
in a specific store and are currently active.
- Parameters: StoreId, IsActive
- Use the parameters to filter by store and activity status.
8. Develop a stored procedure to calculate the total stock quantity
for a specific product across all stores.
- Parameters: ProductId
- Output Parameter: TotalQuantity
9. Create a stored procedure to fetch all orders placed by a specific
customer and calculate the total amount spent.
- Parameters: CustomerId
- Output Parameter: TotalAmount
10. Write a stored procedure to deactivate a staff member by their
ID.
- Parameters: StaffId
- Use a variable to update the “active” field.
11. Create a stored procedure to retrieve the top-selling product in a
given store within a date range.
- Parameters: StoreId , StartDate , EndDate
- Use variables to calculate the total quantity sold for each
product and return the top seller.
12. Develop a stored procedure to restock products with low
quantities in a specific store.
- Parameters: StoreId, Threshold, RestockAmount
- Use a variable to check and update quantities below the
threshold.
13. Write a stored procedure to create a new customer and return
their newly generated customer_id.
- Parameters: FirstName, LastName, Email , Phone
- Output Parameter: NewCustomerId
14. Create a stored procedure to get the order status of a specific
order and return its description.
- Parameters: OrderId
- Output Parameter: OrderStatusDescription
- Map order_status values (1, 2, 3, 4) to descriptions (e.g.,
Pending, Processing, etc.).
15. Develop a stored procedure to calculate and return the total
revenue generated by a store within a specific date range.
- Parameters: StoreId , StartDate , EndDate
- Output Parameter: TotalRevenue
16. Write a stored procedure to transfer a staff member to a
different store.
- Parameters: StaffId , NewStoreId
- Update the store_id for the specified staff member.
17. Create a stored procedure to generate a report of all products
sold in a specific category within a date range.
- Parameters: CategoryId , StartDate , EndDate
- Use joins and variables to fetch and format the report.
18. Write a stored procedure to calculate and return the discount
percentage for a specific order item.
- Parameters: OrderId , ItemId
- Output Parameter: DiscountPercent
19. Create a stored procedure to identify and list all products that
are out of stock in a given store.
- Parameters: StoreId
20. Develop a stored procedure to fetch a list of customers who
have placed orders above a certain amount within a date range.
- Parameters: MinOrderAmount , StartDate , EndDate