Thursday, August 21, 2014
Query for user tables without Primary Keys
SELECT sch.name AS SchemaName, obj.name AS TableName
FROM sys.objects obj
INNER JOIN sys.schemas sch
ON obj.schema_id = sch.schema_id
LEFT JOIN sys.objects pk
ON pk.type = 'PK'
AND pk.parent_object_id = obj.object_id
WHERE obj.is_ms_shipped = 0
AND pk.object_id IS NULL
AND obj.type = 'U'
Monday, July 7, 2014
DMV query to find current executing command of a session
SELECT er.session_id,
er.status,
er.command,
er.cpu_time,
er.total_elapsed_time,
sqltext.TEXT
FROM sys.dm_exec_requests er
CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS sqltext
where er.session_id = -- Your Session ID here
Subscribe to:
Posts (Atom)