This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| -- Brent Ozars script: | |
| EXEC dbo.sp_BlitzIndex @SchemaName='dbo', @TableName='TableName', @fullOutput = 1 | |
| */ | |
| -- makes it very easy to spot possible duplicates that can be combined. | |
| SELECT | |
| [i].[name] AS IndexName, | |
| [i].[type_desc] AS IndexType, | |
| STUFF( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| git rm .gitattributes # Removes the .gitattributes file from both the working directory and the Git index (staging area). | |
| git add -A # Stages all changes: added files, modified files, and deletions (like the .gitattributes removal) for the next commit. | |
| git reset --hard # Resets the working directory and index to the last committed state — all staged and unstaged changes are lost. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| EXEC sp_configure 'show advanced options', 1; | |
| RECONFIGURE; | |
| EXEC sp_configure 'xp_cmdshell', 1; | |
| RECONFIGURE; | |
| /************************************************************ | |
| ** Change the value of the @server variable here | |
| *************************************************************/ | |
| DECLARE @Server VARCHAR(255) = 'servername' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # IMPORTANT: !!Generated certs should NOT be used in production!! | |
| $cert = New-SelfSignedCertificate ` | |
| -Subject "CN=sso.servername.it" ` | |
| -KeyAlgorithm RSA ` | |
| -KeyLength 2048 ` | |
| -CertStoreLocation "Cert:\CurrentUser\My" ` | |
| -NotAfter (Get-Date).AddYears(5) ` | |
| -KeyExportPolicy Exportable ` | |
| -Type Custom ` | |
| -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.3") # Code signing usage |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| ORIGINAL SCRIPT: https://lukelowrey.com/sql-server-script-to-automatically-create-indexes-for-foreign-keys/ | |
| TDC: script modifications | |
| - include the schema name when creating the index | |
| - switched to inner join syntax | |
| - switched to using concat for string concatenation | |
| - general cleanup | |
| */ | |
| DECLARE @IndexName TABLE ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SET NOCOUNT ON | |
| DECLARE @current_id INT = 1, | |
| @db_name sysname, | |
| @table_name sysname, | |
| @target_months INT, | |
| @datetime_column sysname, | |
| @sql NVARCHAR(MAX), | |
| @sep VARCHAR(100) = REPLICATE('*', 80) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <# download and install Solarwinds SentryOne Plan Explorer #> | |
| $filenamePlanExplorerInstall = "$env:USERPROFILE\downloads\" + ([string](Get-Date -format "yyyy-MM-dd")) + "_SolarWinds-PlanExplorer.exe" | |
| Start-BitsTransfer -Source 'https://downloads.solarwinds.com/solarwinds/Release/FreeTool/SolarWinds-PlanExplorer.exe' -Destination $filenamePlanExplorerInstall | |
| & $filenamePlanExplorerInstall /install /passive /norestart |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <# | |
| .SYNOPSIS | |
| Generates T-SQL scripts to enable temporal or history tracking for all user tables in a SQL Server database. | |
| .DESCRIPTION | |
| This PowerShell script connects to a specified SQL Server and database, detects the SQL Server version, | |
| and generates T-SQL to enable historical tracking of data changes. | |
| - For SQL Server **2016 or later** (version 13+): | |
| - The script generates ALTER TABLE statements to enable **system-versioned temporal tables**. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <# | |
| .SYNOPSIS | |
| Generates a T-SQL script that adds 'ModifiedBy' and 'ModifiedDate' columns to all user tables in a SQL Server database that do not already have them. | |
| .DESCRIPTION | |
| This script connects to the specified SQL Server and scans for user tables missing the 'ModifiedBy' and 'ModifiedDate' columns. | |
| It then generates a SQL script that: | |
| - Adds these columns with default values. | |
| - Creates AFTER UPDATE triggers to automatically populate these fields. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT CURRENT_USER AS [CURRENT_USER], /*Returns the name of the current security context. If EXECUTE AS has been used, it returns the impersonated user's name. */ | |
| USER AS [USER], /*Similar to USER_NAME(), it returns the database user name and, after EXECUTE AS, the impersonated user. */ | |
| USER_NAME() AS [USER_NAME()], /*Returns the database user name based on the provided ID. If no ID is specified, it returns the current user's name. It also returns the impersonated user's name after EXECUTE AS. */ | |
| SESSION_USER AS [SESSION_USER], /*Returns the name of the user who initiated the session, even if EXECUTE AS has been used. */ | |
| SYSTEM_USER AS [SYSTEM_USER], /*Returns the name of the current security context. If EXECUTE AS has been used, it returns the impersonated user's name. */ | |
| SUSER_NAME() AS [SUSER_NAME()], /*Returns the login name. When called with a server principal ID, it returns the name associated with that ID. */ | |
| ORI |