Click here to Skip to main content
15,850,750 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have more than 1000 Stored procedures, due to some dirty programmers they would have used 'nolock' for stored procedure tables.

Now i am facing lots and lots of issues due to this issue in daily basics.

For some reasons i cant remove all the nolock key words from SP but i need to know in which stored procedure it occurs along with table name.

Example:

Let us consider a store-procedure(sp_user) used two tables (tbl_salary) and (tbl_account) and if one table (tbl_account) end with (NOLOCK) then i need to return following details.

S.N SP_Name Table_name
1 sp_user tbl_account`


I don't need Stored procedure name,i know that it can be get optained using routine_definition like clause, i need the table name only.

Any help will me much appreciated...
Posted
Comments
virusstorm 19-Jun-15 11:17am    
Your best approach will probably be to write a RegEx that will extract the table name from your stored procedure.

I'm hoping you have the procedures in a database project (consider doing so if you don't). You simply need to run your RegEx against the stored procedure files to find all of the tables.

If you don't, you can query the "sys.syscommentsview" for your stored procedure definition. You can write a quick console application that can run your RegEx against the "text" column.
CHill60 19-Jun-15 18:17pm    
"dirty programmers"? There are some very good reasons for using nolock.
To be honest, all you need is the Stored Proc name, because if you want to remove the nolock then you need to edit the SP. End Of. So the table name is irrelevant - there is nothing you can do to the table to change the way the SP works
Ragul M 22-Jun-15 2:24am    
I agree with you , but in my DB many corn job running every second, So i need table name along with sp name..
CHill60 22-Jun-15 8:16am    
I don't know what a "corn job" is and how often they run is not relevant to editing Stored Procedures. I still don't understand why you need the table name, it won't help you decide whether or not the nolock can be or should be removed (you haven't explained the "some reason" why you cannot remove all of them).
However, virusstorm has given you some ideas on how this could be done. I'm personally not keen on complex RegEx expressions, but remember that you may need to cater for table aliases and fully qualified table names (in other words that regex will be very complex)
If it was me I would just use standard string handling as this is a one-off exercies
Ragul M 24-Jun-15 9:20am    
Actual reason is in my site i have made a user to login with 5 invalid attempts, some times due to heave usage my db gets ideal and stop responding , but the user will refresh that page for 5 times without knowing which means he has attempt to login with wrong password for 1st time, since database is not responding he refreshed many times so the data will be in 'Q' and i have used nolock in one table and not in another table so for the invalid attempt of that user will be logged in a table without responding and finally he will be banned out.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900