Last active
May 8, 2022 03:46
-
-
Save data-goblin/a49d42a39dec24c8ca86d6b17c32ba09 to your computer and use it in GitHub Desktop.
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
///////////////////////////////////////////////////////////////////////////////////////////// | |
// | |
// Evaluates a DMV to get the number of RI Violations | |
// Requires the appropriate privileges and that you are selecting a table | |
// | |
///////////////////////////////////////////////////////////////////////////////////////////// | |
// Query the DISCOVER_STORAGE_TABLES DMV to find RI violations for the selected table | |
var query = "SELECT [RIVIOLATION_COUNT], [DIMENSION_NAME] FROM $SYSTEM.DISCOVER_STORAGE_TABLES WHERE [DIMENSION_NAME] = '" + Selected.Table.Name + "'"; | |
///////////////////////////////////////////////////////////////////////////////////////////// | |
// | |
// Initialize Variables | |
// | |
///////////////////////////////////////////////////////////////////////////////////////////// | |
int RI_Violations = 0; | |
int _nrows = 0; | |
string _emptystring = ""; | |
string _RI_string = ""; | |
List<string> RI_Tables = new List<string>(); | |
///////////////////////////////////////////////////////////////////////////////////////////// | |
// | |
// Execute Query | |
// | |
///////////////////////////////////////////////////////////////////////////////////////////// | |
using(var daxReader = ExecuteReader(query)) | |
{ | |
// Read the query results, iterating through each row in the rowset | |
while(daxReader.Read()) | |
{ | |
var rowValues = new object[daxReader.FieldCount]; | |
daxReader.GetValues(rowValues); | |
var row = rowValues.Select(v => v == null ? "" : v).Cast<object>().ToList(); | |
// Count the number of Row violations, adding the value from each row in the iteration | |
RI_Violations = RI_Violations + Convert.ToInt32(row.ElementAt(0)); | |
// Reset the row string | |
_RI_string = _emptystring; | |
foreach ( var i in row ) | |
{ | |
// Get the index of the item in the list | |
int index = row.FindIndex(a => a == i); | |
// Append the field values for the row together into a single string | |
_RI_string = _RI_string + row[index] + " - "; | |
} | |
// Add the row to the list RI_Tables | |
RI_Tables.Add(_RI_string); | |
} | |
// Close the reader | |
daxReader.Close(); | |
} | |
///////////////////////////////////////////////////////////////////////////////////////////// | |
// | |
// Report out the result | |
// | |
///////////////////////////////////////////////////////////////////////////////////////////// | |
Info ( "There are " + RI_Violations + " RI Violations from the '" + Selected.Table.Name + "' table."); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment