Skip to content

Instantly share code, notes, and snippets.

@sirsql
sirsql / GetSqlServerColumnUse.sql
Last active April 18, 2022 23:47
Return a list columns in the database and for each column a comma delimited list of tables in which that column appears
/* Return a list columns in the database and for each column a comma delimited list of tables in which that column appears */
SELECT
c.name AS ColumnName
, STRING_AGG(CONCAT( QUOTENNAME(s.name), '.', QUOTENAME(t.name)), ', ')
WITHIN GROUP (ORDER BY CONCAT(QUOTENAME(s.name), '.', QUOTENAME(t.name))) AS TableListForColumn
, COUNT(*) AS TableUsageCountForColumn
FROM sys.tables AS t
JOIN sys.columns AS c ON c.object_id = t.object_id
JOIN sys.schemas AS s ON s.schema_id = t.schema_id
GROUP BY c.name
@sirsql
sirsql / Get-NewPassword.ps1
Created May 4, 2022 17:15
Creates a new password of specified length
#Creates a new password of specified length using characters within the random character set
function Get-NewPassword ([int32]$PasswordLength) {
if (!$PasswordLength) { $PasswordLength = 42 }
[string]$CharacterSet = 'abcdefghijklmnoprstuvwxyzABCDEFGHIJKLMONPQRSTUVWXYZ!@#$%^&*()[]{},.<>/?'
$RandomChar = 1..$PasswordLength | ForEach-Object { Get-Random -Maximum $CharacterSet.length }
$ofs = ""
[string]$CharacterSet[$RandomChar]
}