There are a couple of queries that you can run while your query is
executing to see if there is anything else running that is blocking the
execution. The first will show all running activities and identify if any
are blocking one another. The second is just a handy script to see what's
running currently.
/******************************************* Find blocking SPIDS
*******************************************/ SELECT s.spid, BlockingSPID =
s.blocked, DatabaseName = DB_NAME(s.dbid), s.program_name,
s.loginame, ObjectName = OBJECT_NAME(objectid, s.dbid), Definition =
CAST(text AS VARCHAR(MAX)) FROM sys.sysprocesses sCROSS APPLY
sys.dm_exec_sql_text (sql_handle) WHERE s.spid > 50
/******************************************* Find all running queries
*******************************************/ SELECT sqltext.TEXT,
req.session_id, req.status, req.command, req.cpu_time,
req.total_elapsed_time FROM sys.dm_exec_requests req CROSS APPLY
sys.dm_exec_sql_text(sql_handle) AS sqltext
If these don't show anything blocking your query, you may want to look at
using query hints to force the use of a particular index. SQLServer will
somtimes choose a poor execution plan. You can give it hints on which
index to use at the table level using something like the following: SELECT
* FROM tablename WITH (INDEX({indexname})) WHERE xxxx. A good primer on
using index hints can be found here:
http://blog.sqlauthority.com/2009/02/08/sql-server-introduction-to-force-ind
ex-query-hints-index-hint-part2/
Hope this helps,
-- Jeff
-------- Original Message --------
> From: "Brook Davies" <
cft...@logiforms.com>
> Sent: Thursday, December 05, 2013 10:27 AM
> To: "cf-talk" <
cf-...@houseoffusion.com>
> Subject: Simple SQL Query sometimes really Slow?
>
Archive:
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:357292