Assignment Overview
In this assignment, you will build a complete Inventory Management System backend using stored procedures for business operations, functions for calculations, and triggers for automatic auditing.
Stored Procedures
Input/output parameters, control flow
Functions
Scalar, table-valued, deterministic
Triggers
BEFORE, AFTER, INSERT/UPDATE/DELETE
The Scenario
SmartStock Inventory System
SmartStock needs a programmable database backend. All business logic should be encapsulated in stored procedures, with reusable functions for calculations.
"We need procedures for orders, inventory updates, and reports. Every stock change must be automatically logged in our audit table."
Implementation Tasks
Stored Procedures (6 procedures)
sp_CreateOrder- Create new order with itemssp_UpdateStock- Adjust inventory levelssp_ProcessReturn- Handle product returnssp_GetInventoryReport- Generate stock reportsp_SearchProducts- Search with multiple filterssp_TransferStock- Move stock between warehouses
User-Defined Functions (5 functions)
fn_CalculateDiscount- Apply tiered discount pricingfn_GetStockStatus- Return stock level categoryfn_CalculateTax- Compute tax based on regionfn_GetLowStockItems- Table-valued: items below reorderfn_GetProductHistory- Table-valued: product transactions
Triggers (4 triggers)
trg_AuditStockChange- Log all inventory changestrg_UpdateLastModified- Auto-update timestamptrg_PreventNegativeStock- BEFORE trigger validationtrg_NotifyLowStock- Alert when stock below threshold
Submission Guidelines
GitHub Repository
- Create a repository named
sql-assignment-8-stored-objects - Include
procedures.sqlwith all stored procedures - Include
functions.sqlwith all UDFs - Include
triggers.sqlwith all triggers - Include
test-cases.sqldemonstrating each object
Grading Rubric
| Criteria | Points |
|---|---|
| Stored procedures (6 × 15 pts) | 90 |
| User-defined functions (5 × 10 pts) | 50 |
| Triggers (4 × 8.75 pts) | 35 |
| Total | 175 |