Tuesday, 19 May 2015

Windows 8 - how to enable run as different user

Enabling the Run as Different User Option

Press the Windows + R key combination to bring up a run box, type gpedit.msc and hit enter.



Now you will need to drill down into:
User Configuration\Administrative Templates\Start Menu and Taskbar


On the right-hand side you will see a setting called Show “Run as different user” command on Start, double click on it.

image

Now switch the radio button from “Not Configured” to “Enabled”,  then click on the OK button.

image

Now we will need to force the policy to take effect on your PC, to do this press the Windows + R key combination, when the run box opens the following then hit enter:
gpupdate /force


That is all there is to it. Now you can easily run applications as a different user from the Start Screen.

Thursday, 14 May 2015

Find locks per table

use dbnamehere;
SELECT
CASE DTL.REQUEST_SESSION_ID
 WHEN -2 THEN 'ORPHANED DISTRIBUTED TRANSACTION'
 WHEN -3 THEN 'DEFERRED RECOVERY TRANSACTION'
 ELSE DTL.REQUEST_SESSION_ID END AS SPID,
DB_NAME(DTL.RESOURCE_DATABASE_ID) AS DATABASENAME,
SO.NAME AS LOCKEDOBJECTNAME,
DTL.RESOURCE_TYPE AS LOCKEDRESOURCE,
ES.LOGIN_NAME AS LOGINNAME,
ES.HOST_NAME AS HOSTNAME,
DTL.RESOURCE_SUBTYPE AS ResourceSubType,
DTL.REQUEST_MODE AS LOCKTYPE,
ST.TEXT AS SQLSTATEMENTTEXT,
CASE TST.IS_USER_TRANSACTION
 WHEN 0 THEN 'SYSTEM TRANSACTION'
 WHEN 1 THEN 'USER TRANSACTION' END AS USER_OR_SYSTEM_TRANSACTION,
AT.NAME AS TRANSACTIONNAME,
DTL.REQUEST_STATUS
FROM
SYS.DM_TRAN_LOCKS DTL
JOIN SYS.PARTITIONS SP ON SP.HOBT_ID = DTL.RESOURCE_ASSOCIATED_ENTITY_ID
JOIN SYS.OBJECTS SO ON SO.OBJECT_ID = SP.OBJECT_ID
JOIN SYS.DM_EXEC_SESSIONS ES ON ES.SESSION_ID = DTL.REQUEST_SESSION_ID
JOIN SYS.DM_TRAN_SESSION_TRANSACTIONS TST ON ES.SESSION_ID = TST.SESSION_ID
JOIN SYS.DM_TRAN_ACTIVE_TRANSACTIONS AT ON TST.TRANSACTION_ID = AT.TRANSACTION_ID
JOIN SYS.DM_EXEC_CONNECTIONS EC ON EC.SESSION_ID = ES.SESSION_ID
CROSS APPLY SYS.DM_EXEC_SQL_TEXT(EC.MOST_RECENT_SQL_HANDLE) AS ST
WHERE RESOURCE_DATABASE_ID = DB_ID()
--and login_name
--and SO.name  like ''
ORDER BY DTL.REQUEST_SESSION_ID

List recent reports executed

SELECT TOP 1000

c.path

,c.name

,ELS.InstanceName

,ELS.ReportID

,ELS.UserName

,ELS.Format

,ELS.Parameters

,ELS.ReportAction

,ELS.TimeStart

,ELS.TimeEnd

,ELS.TimeDataRetrieval

,ELS.TimeProcessing

,ELS.TimeRendering

FROM [ReportServer].[dbo].[DataSource] ds

JOIN [ReportServer].[dbo].[ExecutionLogStorage] ELS on ELS.ReportID = ds.ItemID

JOIN [ReportServer].[dbo].[Catalog] c on c.ItemID = ds.ItemID

where ds.Name = 'DbNameHere'

order by TimeStart desc

Viewing your cores

Viewing your cores

Open a command prompt by pressing Windows Key + x + a and paste in the following command:
WMIC CPU Get /Format:List

Use WMIC to get the number of cores of your CPU

Scroll down and look for NumberOfCores and NumberOfLogicalProcessors.  From the graphic above you can see I have a quad core processor.

Friday, 8 May 2015

Get All Table Row Counts

-- run at database level
SELECT sc.name +'.'+ ta.name TableName

,SUM(pa.rows) RowCnt

FROM sys.tables ta

INNER JOIN sys.partitions pa

ON pa.OBJECT_ID = ta.OBJECT_ID

INNER JOIN sys.schemas sc

ON ta.schema_id = sc.schema_id

WHERE ta.is_ms_shipped = 0 AND pa.index_id IN (1,0)

GROUP BY sc.name,ta.name

ORDER BY SUM(pa.rows) DESC

Thursday, 7 May 2015

List Recent SQL Agent Jobs

USE msdb
Go
SELECT j.name JobName,h.step_name StepName,
CONVERT(CHAR(10), CAST(STR(h.run_date,8, 0) AS dateTIME), 111) RunDate,
STUFF(STUFF(RIGHT('000000' + CAST ( h.run_time AS VARCHAR(6 ) ) ,6),5,0,':'),3,0,':') RunTime,
h.run_duration StepDuration,
    case h.run_status when 0 then 'Failed'
    when 1 then 'Succeeded'
    when 2 then 'Retry'
    when 3 then 'Cancelled'
    when 4 then 'In Progress'
end as ExecutionStatus,
h.message MessageGenerated
FROM sysjobhistory h
inner join sysjobs j
ON j.job_id = h.job_id

    LEFT JOIN (
                SELECT
                    [job_id]
                    , [run_date]
                    , [run_time]
                    , [run_status]
                    , [run_duration]
                    , [message]
                    , ROW_NUMBER() OVER (
                                            PARTITION BY [job_id]
                                            ORDER BY [run_date] DESC, [run_time] DESC
                      ) AS RowNumber
                FROM [msdb].[dbo].[sysjobhistory]
                WHERE [step_id] = 0
            ) AS [sJOBH]
            ON j.[job_id] = [sJOBH].[job_id]
            AND [sJOBH].[RowNumber] = 1

--where j.job_id = 'F04E5D3B-C873-448A-805C-C6309A92FFFF'
ORDER BY h.run_date, h.run_time desc