Bird
0
0

You need to create a reusable SQL routine that calculates the discount price and also logs the discount application in a table. Which approach is best?

hard📝 Application Q15 of 15
SQL - Stored Procedures and Functions
You need to create a reusable SQL routine that calculates the discount price and also logs the discount application in a table. Which approach is best?
AUse a single function to calculate discount and log the discount inside it.
BUse a function to calculate discount and a procedure to log the discount.
CUse a procedure to calculate discount and return the discounted price.
DUse a procedure only to calculate discount and log the discount.
Step-by-Step Solution
Solution:
  1. Step 1: Separate calculation and action

    Functions should be used for calculations returning values; procedures for actions like logging.
  2. Step 2: Apply best practice

    Use a function to return the discount price, and a procedure to perform the logging task separately.
  3. Final Answer:

    Use a function to calculate discount and a procedure to log the discount. -> Option B
  4. Quick Check:

    Functions calculate; procedures perform tasks [OK]
Quick Trick: Calculate with functions; log with procedures [OK]
Common Mistakes:
  • Trying to do logging inside functions
  • Expecting procedures to return values
  • Mixing calculation and side effects in one routine

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes