Search for keyword in T-SQL stored procedures [duplicate] - sql-server

This question already has answers here:
How do I find a stored procedure containing <text>?
(21 answers)
Closed 8 years ago.
Whenever I'm developing stored procedures, I often need to do a find/replace or simply just find a keyword (string literal) inside the code. I do this by exporting all of the schema and then doing a find in a text editor, like TextPad.
Where are stored procedures actually stored in the database itself, when you click "Modify" on any stored procedure? That way I can find them and find text in the source code using some keyword without doing an export each time. Is this possible?

Another great tool that would accomplish this is SQL Search, by Red Gate. It's free and easy to use, I use it all the time. It works as an add-in for SSMS.

Related

Script multiple CREATE TABLEs in SQL SSMS? [duplicate]

This question already has an answer here:
How do I generate scripts for all tables with single stroke in SQL Server 2000? [closed]
(1 answer)
Closed 3 years ago.
I have a database with many tables that have been periodically updated over the years (not by me). I would like to make CREATE TABLE scripts for all of the tables.
It appears Script table as... only works on a single table at a time. Is there a way to script out all of the tables in a database?
In SSMS, Right Click the Database, go to Tasks -> Generate Scripts.
In the second window, select Select specific database objects and tick Tables:
Choose where you want the results to to go, File, Clipboard or a new Query Window
Check all the settings are correct
Finish. Consume your file/clipboard.

Updating a table in SQL Server Management Studio [duplicate]

This question already has answers here:
How to auto daily execute queries SQL Server? [duplicate]
(3 answers)
Closed 3 years ago.
I am using SQL Server Management Studio v17.4
I have a view v_fetch_rates. I have created a table using the command
SELECT *
INTO RATES
FROM v_fetch_rates
My question is how do I update the table RATES on daily basis automatically? Is there a way to do it by existing view or do I need to write stored procedure for this?
I did some googling but it confused me even more.
I have never created a job before so any help/resources to refer would help a lot.
If the issue is that the view is slow (because of its definition or the amount of data it returns) and you want to materialized the data in order to improve performance you can simply create a indexed view.
The idea is simple - creating an index on the view forces the engine to materialized it. Of course, there are various limitations and requirements of having index view. You can find more information in the specified link.
If you just want to have the data in a table and populated in on daily basis, you can:
create simple stored procedure which is truncating the current table and populating the data again calling the view
create a complex routine, which will modify (insert/update/delete) data only if needed

Log of stored procedure parameters? [duplicate]

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Tracing a stored procedure’s parameters handling
Is there any out-of-the-box functionality within SQL Server 2008 that will allow me to see a log of procedures executed, and the parameters passed?
We have a stored procedure whose return is used to determine if a user can log in to our application or not, and the stored procedure is returning some unexpected results. I'm trying to troubleshoot by seeing if the user ID is getting garbled as it's passed to the stored procedure, but I can't quite seem to find where I could go to check that.
Does such a log/viewer exist?
You can use SQL Trace, or SQL profiler, which is essentially a GUI for the same tool.
Details of SQL Trace here msdn.microsoft.com/en-us/library/ms191006(v=sql.105).aspx
Profiler here msdn.microsoft.com/en-us/library/ms181091.aspx
Pete has the right answer if you need to track everything that is run, but if you can modify the procedures yourself you can add logging functionality (something like inserting to a table with the relevant details) directly to the procedure. This avoids the potentially large performance impact of the profiler.

How to see what stored procs/functions/triggers rely on a column in a table? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Find a specific column entry in an unknown table in a database?
how to search Sql Server 2008 R2 stored procedures for a string?
Hello I'm trying to figure out a fairly complex SQL Server(2008 in 2000 compatibility) database. There are 3 columns in a table I'm particularly concerned with. I've searched the code of our application and it seems to make no direct usage of these 3 columns but I know somewhere in the database they are populated and used. So it must be in triggers, functions, and/or stored procedures.
What is the best way of figuring out where to look for the code that populates these 3 columns?
If you need to find database objects (e.g. tables, columns, triggers) by name - have a look at the FREE Red-Gate tool called SQL Search which does this - it searches your entire database for any kind of string(s).
It's a great must-have tool for any DBA or database developer - did I already mention it's absolutely FREE to use for any kind of use??

SQL Server: Copy Stored Procedures [duplicate]

This question already has answers here:
SQL Server - copy stored procedures from one db to another
(11 answers)
Closed 9 years ago.
Is there an easy way to copy all stored procedures from one database to another? I have SQL Management Studio installed.
In SQL 2005 and 2008 management: Right click on the database, choose tasks -> generate scripts. You should be able to follow the directions in the wizard from there.
In Sql 2000 you can actually just select the procedures you want to copy, ctrl+c to copy them, then paste them into a new query window for the other DB and run it.
You can script objects out with SQL Management Studio by right clicking the database name and clicking script objects(or something like that I'm not on my Windows machine right now to check). You can select to do just the stored procs and select to have all the output go to one file instead of 1 file per an object. Once you have them in one file you can run that file against your database.
Also look into Red Gate Software's tool called SQL Compare
http://www.red-gate.com/products/SQL_Compare/index.htm
It's not free but does have a free trial.

Resources