Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
sureshot
Yak Posting Veteran
72 Posts |
Posted - 2005-10-06 : 14:42:46
|
| I have 3 recordsets that I'd like returned. I was considering whether to put the code to return them all in one SP or make an SP that calls 3 separate SP's and I came up with the following guidelines:Use single monolithic SP if- passing large parameters- duplicating operations inside each one (like splitting a CSV string that is needed in each)- passing data between them through temp tables (causes recompiles)Use three SP's called by one otherwise- more maintainable- each SP has its own execution plan so if it needs to recompile it won’t recompile your whole big procedure.Anything else to consider? Locking issues? |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2005-10-06 : 15:15:27
|
| You forgot regression testing when you need to make a change. That means, you should test the functionality of all three instead of one.Make 3What's so hard to clone anyway?Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2005-10-07 : 02:23:30
|
Do you mean you need to do something like:SELECT * FROM Table1 WHERE COL1 = 'FOO'SELECT * FROM Table2 WHERE COL2 = 'BAR'SELECT * FROM Table3 WHERE COL3 = 'FOOBAR'(obviously more complicated!)if so isn't there a case for putting them in one Sproc so that the query plan covers the whole job?If you are going to do:IF @PARAM1 = 1 SELECT * FROM Table1 WHERE COL1 = 'FOO'ELSEIF @PARAM1 = 2 SELECT * FROM Table2 WHERE COL2 = 'BAR'ELSEIF @PARAM1 = 3 SELECT * FROM Table3 WHERE COL3 = 'FOOBAR'END then I would probably replace the SELECTs with EXEC Sproc calls instead.Kristen |
 |
|
|
sureshot
Yak Posting Veteran
72 Posts |
Posted - 2005-10-07 : 08:36:31
|
| Something likeCREATE mod1SP AS SELECT * FROM Table1 WHERE COL1 = 'FOO'GOCREATE mod2SP AS SELECT * FROM Table2 WHERE COL2 = 'BAR'GOCREATE mod3SP AS SELECT * FROM Table3 WHERE COL3 = 'FOOBAR'GOCREATE modularSP AS EXEC mod1SP EXEC mod2SP EXEC mod3SPGOCREATE monoSP AS SELECT * FROM Table1 WHERE COL1 = 'FOO' SELECT * FROM Table2 WHERE COL2 = 'BAR' SELECT * FROM Table3 WHERE COL3 = 'FOOBAR'GOI'm trying to decide between EXEC modularSP and EXEC monoSP to get 3 recordsets. |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2005-10-07 : 08:50:17
|
| I would use monoSP (so that the query plan covers the lot) than I would use modularSP (ratio about 90:10 I would guess - I would use the modularSP if its components were going to get reuse elsewhere and it was important to centralise the logicKristen |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
|
|
|