Category Archives: T-SQL

SQL Agent jobs, linked servers and minimal privileges

Basically, this issue is all described here… https://support.microsoft.com/en-us/kb/2492477 In a nutshell, a T-SQL job executes in the context of the job owner. If the job owner is sa or another member of the sysadmin role is is able to make … Continue reading

Posted in Security, T-SQL, Tips | Comments Off on SQL Agent jobs, linked servers and minimal privileges

SQL Server Job Execution Status Output

It is not possible to use INSERT….EXEC to call sp_help_job to output the results into a table for querying e.g you want to get the execution status of a job using sp_help_job through some form of automation.The error you will … Continue reading

Posted in T-SQL, Tips | Comments Off on SQL Server Job Execution Status Output

Scripting out all indexes

The following script will script out all indexes and can be modified to do just clustered or non-clustered by adjusting the upper CTE query WHERE clause (highlighted with comments). You can add the DROP_EXISTING=ON if you want to move an … Continue reading

Posted in T-SQL | Comments Off on Scripting out all indexes