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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Stored Procedures in a Table

Author  Topic 

DigitalDiamond
Starting Member

4 Posts

Posted - 2005-03-17 : 07:42:52
I am trying to find out if its possible to place stored procedured in a table as text so that the procedures can be dynamically exracted and run on different databases etc dependant on the results of other queries or procedures. Any help on this would be great even if its just a link to a page etc.

robvolk
Most Valuable Yak

15732 Posts

Posted - 2005-03-17 : 07:54:30
The text for stored procedures is already stored in syscomments, it wouldn't be worthwhile to store them in a database.

If you're talking about setting up a code maintenance database, you would be better off with a real source control system like CVS, or if you're using Visual Studio, Source Safe. It's much easier to use and organize stored procedures as files than it is as rows in a table (I've done both, never gonna do the latter again)

How you store and manage procedure code does not affect how you execute them. You'd still have to create the procedure in that database before you can call it. Creating them on the fly is not practical or efficient. If you have conditional logic to determine which procedure to run, it's nothing more than:

IF EXISTS(SELECT * FROM myTable WHERE lastname='Connor' AND firstname='Sarah')
EXECUTE Kill_Sarah_Connor
...
IF EXISTS(SELECT * FROM myTable WHERE lastname='Schwarzenegger' AND firstname='Arnold')
EXECUTE Become_Governator
Go to Top of Page
   

- Advertisement -