Chapter10 SQL
Chapter10 SQL
Chapter10 SQL
W R I T I N G F U N C T I O N S A N D S TO R E D P R O C E D U R E S I N S Q L S E R V E R
Etibar Vazirov
Slides credit: Meghan Kwartler
What is a stored procedure?
What?
Routines that
Improved Security
Etibar
Meghan Vazirov
Kwartler
Slides credit:
IT C ons ultantMeghan Kwartler
Why stored procedures for CRUD?
Decouples SQL code from other application
layers
Improved security
Improved security
Performance
Etibar
Meghan Vazirov
Kwartler
Slides credit:
IT C ons ultantMeghan Kwartler
Ways to EXECute
No output parameter or return value
+ +
| TotalRideHrs |
| +
| 77733 |
+ +
+ + +
| TripDate | TripHours |
| + |
| 2017-01-05 | 200 |
+ + |
Etibar
Meghan Vazirov
Kwartler
Slides credit:
IT C ons ultantMeghan Kwartler
To handle errors or not
What is error handling? What happens without error handling?
EXECUTE dbo.cusp_TripSummaryCreate
@TripDate = '1/32/2018',
@RideHrs = 100,
@ErrorMsg = @ErrorMsgOUT OUTPUT
ErrorMessage
Simple & easy to use Generates new error and cannot access
details of original error (e.g. line number
Statements following will NOT be executed
where error originally occurred)
Statements following can be executed