Wednesday, July 13, 2011

SQL Stored Procedures Performance

I've been told there are performance gains when using 'Stored Procedures'. Lately I've been wondering what the real gains of performance are and does it relate to a simple select statement?

First we need to create a test set of tables:

Now some code to generate data for the tables:

Now lets make the store procedure to select results:

And now the code we used to test the execution time of cfquery and cfstoredproc:


Now the results I got are very mixed. Sometimes the procedure is faster; sometimes it is not. I've never done anything like this before so I'm wondering if EXECUTIONTIME is the best thing to be comparing? Will using a store procedure in cases like this be that much faster (on such a simple select) or is it more for all the other benefits you get with using it?