16

Stored Procedures and Parameters

Keywords Introduced

CREATE PROCEDURE • BEGIN • EXEC • ALTER PROCEDURE • DROP PROCEDURE

Up until now, all our data retrieval has been accomplished with a single SQL statement. Even the set logic seen in the previous chapter involved combining multiple SELECTs into a single statement. Now we’ll discuss a new scenario in which multiple statements can be saved into a single object known as a stored procedure.

In broad terms, there are two general reasons for using stored procedures:

  • To save multiple SQL statements in a single procedure

  • To use parameters in conjunction with SQL statements

Stored procedures can, in fact, consist of a single SQL statement and contain no parameters. But the real value of stored ...

Get The Language of SQL, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.