Read our blogs, tips and tutorials
Try our exercises or test your skills
Watch our tutorial videos or shorts
Take a self-paced course
Read our recent newsletters
License our courseware
Book expert consultancy
Buy our publications
Get help in using our site
551 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owl trainers only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
Written by Andy Brown
In this tutorial
Let's suppose that you've created the stored procedure described in the previous part of this tutorial:
CREATE PROC spListActors
AS
-- display list of actors
SELECT
ActorName,
ActorGender
FROM
tblActor
You now want to run the spListActors stored procedure, to list out its contents. Below are 3 ways to do this.
The simplest way to run a stored procedure is just to select its name and press F5:
Just double-click on the name of the stored procedure to select it, and then execute it like any other SQL query.
This will produce the results of the SELECT statement included in the procedure:
The first few rows returned by running the procedure.
Note that this method doesn't work if your stored procedure takes parameters (then again, we haven't covered parameters yet!).
A second way to run a stored procedure is to right-click on its name:
Right-click on the name of the procedure in SQL Server Management Studio and choose to execute it as shown here.
Again, this method doesn't work well if your stored procedure takes parameters.
The third way to run a stored procedure is to use the EXECUTE command within a query:
-- 3 ways to run procedure to list out actors
EXEC spListActors
GO
EXECUTE spListActors
GO
spListActors
GO
As the above examples show, you can abbreviate EXECUTE to EXEC or - under certain circumstances - miss it out altogether.
You can learn more about this topic on the following Wise Owl courses:
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2024. All Rights Reserved.