Welcome to Hellrocker's Collections

Hope its all of some use to computer users.............

Friday, March 18, 2011

Continued - Create all basic stored procedures for any table

In addition to my previous post of creating stored procedures for given table...

Here is the query that make use of previously created SP "MyTool" and create stored procedures for all user created tables in the current database...

So you don't need to execute my tool again and again for all the tables...


DECLARE @Count INT
DECLARE @spName VARCHAR(100)
DECLARE @COUNTER INT
SET @COUNTER = 0
SET @Count = 1

SELECT @COUNTER = count(name) FROM sys.tables WHERE name != 'sysdiagrams'
WHILE (@Count<=@COUNTER)
BEGIN
SELECT @spName = SpName FROM
(
SELECT row_number() OVER (ORDER BY name) "RowId", name "SpName" FROM sys.tables WHERE name != 'sysdiagrams'
) "A" WHERE RowId = @Count
EXEC MyTool @spName
SET @Count = @Count + 1
END

Please provide your valuable feedback as it will help me to get better and help others better...

0 comments:

Post a Comment