Saturday, November 9, 2013

Query to Check Currently running queries on Database server

If you are looking for which query executing on server you can use the following query to get the result


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 you want to kill some long running query then you can fire following command to terminate the query execution

kill [process id]


Happy Coding.

Wednesday, October 30, 2013

Generate Random Alpha Numeric Number with

When we require to generate unique id without using NEWID() function of sql, here is the good alternative to generate unique alpha nemuric identifier to use at primary key.

DECLARE @alpha_numeric VARCHAR(16)
SET @alpha_numeric=''

SELECT @alpha_numeric=@alpha_numeric+CHAR(n) FROM
( SELECT TOP 16 number AS n FROM master..spt_values WHERE TYPE='p' and (number between 48 and 57 or number between 65 and 90) ORDER BY NEWID()) AS t

SELECT @alpha_numeric


Hope this will be helpful to generating manual alpha numeric identifier.

Happy Coding!!