tsql

TSQL - Make Excel Link In Output

ben himself's picture

Here is a situation I just came across (boiled down and simplified).  An end user was having to manually find a user id, navigate to an image folder, and then search through hundreds of images to find the one corresponding with that user.  Sure, they were in numerical order, but still, what a pain!  He wanted to generate an excel file with links to files to quickly access the corresponding image. 

Tags: 

Restore All Databases With Most Recent Backup

ben himself's picture

This is a bit of a scary task.  Someone tells you about 87 databases that all need to be restored from the most recent FULL backups. You can either spend the rest of your day pointing and clicking, or you can use some PowerShell power to crank out the script and get on with your day. Here is the PowerShell way.

I don't like to fire-off the actual backups from PowerShell, rather I just use it to script out the restore script.  So, this PowerShell script will output the T-SQL restore script:

(See caution below before running this!)

Tags: 

TSQL – Get Number Of Cores & MaxDOP In Single Query

ben himself's picture

This is a handy script to show the number of cores and MaxDOP in a single output, along with a built-in script to change the value. The built-in script shows up as a query result so you can copy/paste it.

SELECT cpu_count AS [Cores] 
        , (SELECT value_in_use FROM sys.configurations WHERE name = 'max degree of parallelism') AS [MaxDOP]
        , '/*Next Line For SQLCMD Mode*/
:CONNECT ' + @@SERVERNAME + '
sp_configure ''max degree of parallelism'', ''VALUE''; 
RECONFIGURE;
GO
        ' AS [Configure Script]
FROM [sys].[dm_os_sys_info]

Tags: 

Pages

Subscribe to RSS - tsql