PowerShell Method Table Column Differences
This file contains 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
$Table01Param = @{ | |
ServerInstance = 'localhost\SQLServer2K16' | |
Database = 'Pantheon' | |
Query = "SELECT OBJECT_NAME(object_id) AS TableName, name AS ColumnName FROM sys.columns WHERE object_id = OBJECT_ID(N'dbo.TableColumnDifference01', N'U')" | |
} | |
$Table02Param = @{ | |
ServerInstance = 'localhost\SQLServer2K16' | |
Database = 'Pantheon' | |
Query = "SELECT OBJECT_NAME(object_id) AS TableName, name AS ColumnName FROM sys.columns WHERE object_id = OBJECT_ID(N'dbo.TableColumnDifference02', N'U')" | |
} | |
$Table1 = Invoke-Sqlcmd @Table01Param | |
$Table2 = Invoke-Sqlcmd @Table02Param | |
Compare-Object -ReferenceObject $Table1 -DifferenceObject $Table2 -Property ColumnName -IncludeEqual | | |
Select-Object -Property *, | |
@{label = 'HRF'; expression = {switch ($_.SideIndicator) { | |
'==' { 'Both' } | |
'=>' { 'Table 2 Only' } | |
'<=' { 'Table 1 Only'} | |
}} | |
} | | |
Sort-Object -Property ColumnName; | |
# Stats please -- basically how long it takes | |
Measure-Command { | |
Compare-Object -ReferenceObject $Table1 -DifferenceObject $Table2 -Property ColumnName -IncludeEqual | | |
Select-Object -Property *, | |
@{label = 'HRF'; expression = {switch ($_.SideIndicator) { | |
'==' { 'Both' } | |
'=>' { 'Table 2 Only' } | |
'<=' { 'Table 1 Only'} | |
}} | |
} | | |
Sort-Object -Property ColumnName; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment