Which stored procedure using which view? - sql

Description:
My project have lots of stored procedure and also lots of views. I would like to know which stored procedure is using which view. Its quite hard, when i have lots of stored procedure.
I know there are some system table which I can use, but the system tables would not have information for the dynamic queries in my stored procedure.
Please let me know, how can i make it. Is there some tool, or stored procedure for the same. I want to see the relationship between my 'stored procedure' and 'views I used in my stored procedure'.
Thanks in advance

I normally use SQL Search from www.RedGate.com, when I want to search for dependencies, and other relations (such as copy-paste code)
Dynamic SQL is a problem because of its late binding.
HIH,
Henrik Staun Poulsen

Related

Stored procedure fails, but works correctly when it runs manually

I have a stored procedure in SQL Server 2008 R2. It was working correctly, but it stopped working (I did not change the code).
It is something difficult to explain, specially because I can not share the stored procedure's code (company's rules). I will try to explain it as much as possible.
This stored procedure is executed by a software, this software calls two stored procedures. One of the stored procedures works correctly and the another one "fails" (it doesn't do anything and not return any error). Both stored procedures do similar things such as update and insert information, from parameters, in some tables. If I check the software's logs I can see that this software is calling both stored procedures correctly. In fact, the stored procedure does not return any error, it just does not do anything.
When I run this stored procedure manually, I use the same parameters that the software should pass and it works correctly.
I simulated a real case and the software called both stored procedures, one works and the another one did not do anything. Then, I executed the second stored procedure manually with the same parameters and it worked correctly.
In addition, the database's user has enough permission (I guess it, because it was working correctly).
Another important thing is that I have two environments with the same databases. The software calls both stored procedures in both environments. In one of the environments it works correctly and the another environment the software calls both stored procedures, but one of them does not do anything as I have explained here.
Regards and thanks!
First, try to run the stored proc using Profiler to get exactly what is being sent, it may not be sending what you think it should.
Next check the structure of the two databases for the tables/views referenced, any functions in the procs. Make sure to also check permissions. Script the stored procs in both databases and compare. When database on two servers have an issue like this it is often that the servers are not in sync with the exact code they should have.
Also the data may be different resulting in no data that needs to be acted on by the stored proc in one server.
One reason this can happen is the use of temp tables; if they are not available, it may fail, and the scope works differently in a stored procedure than in an interactive session.

Load data while Scrolling with condition query base

http://www.aspsnippets.com/Articles/Load-data-while-Scrolling-Page-down-with-jQuery-AJAX-and-ASPNet.aspx
Above link is having code example to load data on demand(Infinite scroll) is it possible to use join query.
I don't want to create this SQL PROCEDURE is it possible with query. because this procedure has DECLARE the. it's quite difficult to change the SQL PROCEDURE each time.
it will be easy to manage store procedure in place of hard coding
because if anything will require to modify then you can change Store
procedure from server, Otherwise if you have done hard code in
application then you have to publish complete application to change
anything.

Running stored procedure remotely for non IT user

We have a SQL server that we are using for our data warehouse.
We want to give a department the ability to update the data when they want (and not just on schedule).
Was is the best way to do this? We have a SP that we are thinking of calling from a batch script, but is there a more elegant way?
The data will eventually go into Palo Jedox for BI.
I do this sort of thing by writing a ColdFusion web page that the user can run. It could also be done with .net, php, java, etc.
Do not give users the ability to change the tables directly.
Instead, create one or more stored procedures to do the updates/inserts/deletes that you want to do. If it is one record, you can just pass in the values as arguments. If it is a bunch of records, you need a mechanism to transfer larger data into the database -- either reading from a text file or putting it into a table in the database some way.
Be sure the stored procedure has the same owner as the underlying tables. Using owner chaining, the stored procedure will be able to make changes to the tables. At no time can a user make a change to the data directly, only through the stored procedure.
Then, log, log, log everything that gets done. You want to know every time this stored procedure is called to change the data.

Directing ADO queries away from the database

I've got a large number of old Delphi apps accessing a remote SQL Server database using ADO. I would like to get direct those queries to a middleware layer instead of said database. The Delphi clients must run unchanged; I am not the owner of most of them.
Is it possible to do this? If so, how should I go about it?
Don't worry about parsing the T-SQL (both raw T-SQL and stored proc calls, incidentally).
Create a new SQL database, and use a combination of views, T-SQL and managed code to fake up enough database objects for the application to work.
Technique 1: Use tables, but populate them asyncrhonously from the new data source.
Technique 2: Fake the tables and procedures
E.g. you can have a stored procedure which calls managed code to your middleware, to replace the existing stored procedure.
Where the application reads directly from a table, you can use a view, which references a managed table-valued function.
-
You should have no trouble wherever stored procedures are used. If the application sends dynamic SQL you have more of an uphill struggle however.

Is a stored procedure in a database system is a call back mechanism?

Is a stored procedure in a database system is a call back mechanism ?
Not sure I really get the question. Do you mean:
Is a stored procedure in a database
system in itself a call back mechanism?
Or
Do stored procedures have a call back mechanism?
In the first instance, the answer is no, but for me, that question doesn't make much sense.
In the second instance, again the answer is no, if you are wanting a formal dedicated callback machanism. However, a form of callback can be achieved using dynamic SQL and stored procedure parameters.
Consider the following
CREATE Procedure usp_test (#callback varchar(100))
AS
EXEC (#callback)
Here, we are passing the name of the procedure in a string and executing as dynamic SQL. We can, of course append parameters to it if we want. It isn't a tryue callback as we are not passing a reference.
In all honesty, however, it sounds like you don't understand the question. Maybe a better question would have been to enquire as to the meaning of the question?
Databases are basically passive. No calls = no action.
When a database emails you, it is in fact some scheduled client code that calls the database and sends the email.
"A happy database has no users" of course