Query to get time consuming sql statements in SQL Server - sql-server

How can we get information regarding poorly performing sqls(taking too much time for execution)
Does MS SQL server maintains tables/views (Similar to v$sql in Oracle) for storing sql queries.

I Use the SQL Profiler to collect statistic data wich I then can use to nail down where there are need to do some work, tweak indexes and so on.
Here are some tips about monitoring with Profiler:
http://www.developer.com/db/article.php/3490086
http://vyaskn.tripod.com/analyzing_profiler_output.htm

take a look at sys.dm_exec_query_stats and this page. SQL Server 2005+ only.

Related

SQL DMV linking Index Usage to Stored Procedure Usage

I'm auditing & cleaning some SQL 2008 R2 Boxes.
I'm doing a lot of work with:
sys.dm_db_index_usage_stats (Index usage)
sys.dm_exec_procedure_stats (Procedure usage)
These DMVs provide a lot of good performance information.
What I need is a way of linking the results together. i.e. How do I figure out which Stored Procedures are using which indexes?
I've been shredding the XML in the plan cache, but this is very inefficient, does anybody have a better solution?
Use system reports.
In Management studio right click on server or specific database. Select Reports and then Standard reports and select Object execution statistics.
I'm sure you are able to catch queries (if it's necessary) with SQL Server Profiler.

SQL Server - Vertica Connection

I need to query a hp vertica database from SQL Server stored procedure. It is a join query and If I use linked server, it is going to fire as 2 separate selects and join it in the SQL Server . Is there any way I can use ODBC to fire the join query to Vertica from TSQL and get the processed result set back into an SQL table.?
Any other approach to suggest to achieve this ?
You may need to use OPENQUERY syntax in SQL Server, to get the full query sent to Vertica for execution there... There are other possibilities, but we'd need much more detail about what you have in play (especially but not only your current query) to usefully discuss them.

How to get query strings in SQL Server Profiler

I am interested in profiling SQL Server database transactions that are being executed by a java application.
Particularly I am interested in finding out what queries (query strings) get executed as a part of the transaction.
Database I am using is SQL Server 2008.
Right now I am selecting Exec Prepared SQL event and Prepare SQL event in the profiler but that does not give me the query strings that are being executed by the application. I see a bunch of exec statements but nothing more. It doesn't have details as to what query was being executed.
Would anyone have an idea of how can I get access to the query strings?
Regards,
My typicals are:
RPC:Completed.
SP Completed.
SP:StmtCompleted
Exec Prepared SQL
SQL : BatchCompleted
SQL : StmtCompleted
And I pick the TextData columnn (and some others).
Do you know about DMV queries?
http://sqlserverperformance.wordpress.com/2008/01/21/five-dmv-queries-that-will-make-you-a-superhero/
http://sqlserverperformance.wordpress.com/2011/02/04/five-dmv-queries-that-will-make-you-a-superhero-in-2011/

IBM db2 is openquery from MS Sql Server a bad thing? Can it be prevented entirely?

I was told by our IT team that we cannot use the Openquery command in MS Sql Server anymore. They claimed it was possible to slow down the server because every query requires a full table load, and all queries slow it down, etc.etc.
I was somewhat puzzled by this as I thought an OpenQuery command was similar to the 'passthrough' query in Access. The query goes to the IBM server, which executes the command and only sends the results back to SQL Server. I have read through OpenQuery on the internet and nothing I've read makes me believe that it loads or sends a whole table and then SQL Server filters the results.
I assume its possible for them to lock down the DB2 servers and prevent linked servers from SQL Server, but for my future knowledge can someone explain any perils to using OpenQuery when connecting to IBM DB2?
Thanks,
Please read this. Can you avoid OpenQuery? The best alternative would be to use a store procedure command or at least craft a EXECSQL with a SP target.

How to audit SQL Server 2008 queries through WCF Services?

I want to save any kind of log/tables with every query executed by my application.
I know I could do this by coding it (before I make any query, I insert a new row in a log table with the query and the user who is executing it.
I have read it can be done automatically but I'm not sure how can it work with WCF Services. I mean every query is going to be executed by the same SQL user and this wouldn't be very useful for audit operations (I need to know WHO made every query, and users will be validated against my own users tables).
Have you ever had a similar scenario? Thanks in advance!
As a starting point it may be worth looking into doing this via SQL Server Profiler. You can normally find this in the Tools Menu in Management Studio.
You can set up a trace to capture all SQL run on a server. More importantly you have a myriad of filter options which can be applied so that you only capture the data you are interested in (e.g. DatabaseName, UserName).
This information can be stored directly in a SQL Table, which should give you the abillity to join onto. Of course running anything like this will result in some overhead on the SQL box.
You can try the SQL Server Audit feature. It audits singe or groups of events both on server and database level. However, be advised that the database level auditing is available in SQL Server Enterprise and Developer editions only

Resources