|
| |
Almost always during our testing or R&D we
might need to create some stored procedure(s) which would be deleted later. In
my experience I have learnt that it’s really a pain to create stored
procedures with different fancy names and later delete each one without
fail.
What I meant is
this?
Create procedure sampleSP_Authors
As
Select au_id, au_lname, au_fname
from
authors Go
Create
procedure sampleSP_AuthorsALL As
Select * from
authors Go
|
If we need to delete these SP’s, created
for testing purpose within PUBS database, we need to call that many drop proc
statements like,
Drop Procedure
sampleSP_Authors Drop Procedure
sampleSP_AuthorsALL
|
and so on ...
Work aroundCreate procedure sampleSP_Authors;1
As
Select au_id, au_lname, au_fname
from
authors Go
Create
procedure sampleSP_Authors;2 As
Select * from
authors Go
|
Pay attention to "; integer value"
after the procedure name. We can use the same procedure name with different
numbers to group procedures (of same name) like shown in the above samples.
This way for testing or R&D purpose we can keep a common name to
ALL procedures and just change the integer value alone. In
this way, it’s enough if we just call "Drop Procedure sampleSP_Authors" -
it would delete a group of stored procedure with a single drop procedure
statement.
For executing the SP
sampleSP_Authors;2 use the below syntax:
Note: Using
"ProcedureName;1" and "ProcedureName" alone are one and the same.
i.e.,
Exec sampleSP_Authors;1
Exec
sampleSP_Authors
|
Both the above statement would return the same
result only. To understand it better try to alter the SP sampleSP_Authors;1
using the below code snippet:
Alter Proc sampleSP_Authors
As
Select au_id, city,state,zip from
authors
|
Now if we run "Exec sampleSP_Authors;1" it would
return the result containing au_id, city, state and zip from authors
table. That’s cool isn’t it?
ConclusionIn this article we saw a cool feature of SQL
Server for grouping stored procedures of same name. Though this can be used in
testing or R&D environment, I have never seen a real use of it in production
environment. Hope this article was useful to you.
If you need any further clarification on
this or do you have any SQL doubt to be clarified does get in touch with me
(http://vadivel.thinkingms.com
or vmvadivel@gmail.com).
Obviously I won’t guarantee that I would provide a solution in all cases
but surely would try my best J |
.NET Force is optimised for
Microsoft Internet Explorer 5 browsers.
Copyright © 2004 .NET Force.
Terms and Condition. All rights reserved.
|
 |
|