How can I compare these two sets using all their attributes, and ensure they are identical ?--1st setSELECT TABLE_DATA.name AS TableName , INDEX_DATA.name AS IndexName , INDEX_DATA.type_desc AS IndexType , STUFF(( SELECT ', ' + COLUMN_DATA_KEY_COLS.name FROM sys.tables AS T INNER JOIN sys.indexes INDEX_DATA_KEY_COLS ON T.object_id = INDEX_DATA_KEY_COLS.object_id INNER JOIN sys.index_columns INDEX_COLUMN_DATA_KEY_COLS ON INDEX_DATA_KEY_COLS.object_id = INDEX_COLUMN_DATA_KEY_COLS.object_id AND INDEX_DATA_KEY_COLS.index_id = INDEX_COLUMN_DATA_KEY_COLS.index_id INNER JOIN sys.columns COLUMN_DATA_KEY_COLS ON T.object_id = COLUMN_DATA_KEY_COLS.object_id AND INDEX_COLUMN_DATA_KEY_COLS.column_id = COLUMN_DATA_KEY_COLS.column_id WHERE INDEX_DATA.object_id = INDEX_DATA_KEY_COLS.object_id AND INDEX_DATA.index_id = INDEX_DATA_KEY_COLS.index_id AND INDEX_COLUMN_DATA_KEY_COLS.is_included_column = 0 ORDER BY INDEX_COLUMN_DATA_KEY_COLS.key_ordinal FOR XML PATH('') ), 1, 2, '') AS ColumnLists , STUFF(( SELECT ', ' + COLUMN_DATA_INC_COLS.name FROM sys.tables AS T INNER JOIN sys.indexes INDEX_DATA_INC_COLS ON T.object_id = INDEX_DATA_INC_COLS.object_id INNER JOIN sys.index_columns INDEX_COLUMN_DATA_INC_COLS ON INDEX_DATA_INC_COLS.object_id = INDEX_COLUMN_DATA_INC_COLS.object_id AND INDEX_DATA_INC_COLS.index_id = INDEX_COLUMN_DATA_INC_COLS.index_id INNER JOIN sys.columns COLUMN_DATA_INC_COLS ON T.object_id = COLUMN_DATA_INC_COLS.object_id AND INDEX_COLUMN_DATA_INC_COLS.column_id = COLUMN_DATA_INC_COLS.column_id WHERE INDEX_DATA.object_id = INDEX_DATA_INC_COLS.object_id AND INDEX_DATA.index_id = INDEX_DATA_INC_COLS.index_id AND INDEX_COLUMN_DATA_INC_COLS.is_included_column = 1 ORDER BY INDEX_COLUMN_DATA_INC_COLS.key_ordinal FOR XML PATH('') ), 1, 2, '') AS IncludedColumnsFROM sys.indexes INDEX_DATA INNER JOIN sys.tables TABLE_DATA ON TABLE_DATA.object_id = INDEX_DATA.object_id INNER JOIN sys.schemas SCHEMA_DATA ON SCHEMA_DATA.schema_id = TABLE_DATA.schema_idWHERE TABLE_DATA.is_ms_shipped = 0 AND INDEX_DATA.type_desc IN ( 'NONCLUSTERED', 'CLUSTERED' ) -- Avoiding heaps AND INDEX_DATA.name='IndexABC' AND TABLE_DATA.name='MyTable' --2nd setSELECT TableName, IndexName, IndexType, ColumnLists, IncludedColumnsFROM DROPPEDWHERE IndexName='IndexABC' AND TableName='MyTable'
I am trying to avoid UNION due performance issues and a collation error.Any suggestion? I though about a composite join, but 1st set has two complex columns generated from subqueries. I guess I need to put that on a temporary table 1st if I want to use a composite join?Thanks in advance,