Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Declare cTables Cursor LOCAL FORWARD_ONLY FAST_FORWARD READ_ONLY For
- SELECT Distinct
- OBJECT_SCHEMA_NAME(fk.parent_object_id) AS Table1_Scheme_Name,
- OBJECT_NAME(fk.parent_object_id) AS Table1_Name,
- OBJECT_SCHEMA_NAME(fk.referenced_object_id) AS Table2_Scheme_Name,
- OBJECT_NAME (fk.referenced_object_id) AS Table2_Name
- FROM sys.foreign_keys fk
- INNER JOIN sys.foreign_key_columns AS fc ON fk.[OBJECT_ID] = fc.constraint_object_id
- where fk.parent_object_id <> fk.referenced_object_id AND
- OBJECT_SCHEMA_NAME(fk.parent_object_id) NOT IN ('sys', 'pm', 'alog', 'mnt') and
- OBJECT_SCHEMA_NAME(fk.referenced_object_id) NOT IN ('sys', 'pm', 'alog', 'mnt') AND
- OBJECT_NAME(fk.parent_object_id) NOT LIKE '%cube%' and
- OBJECT_NAME(fk.referenced_object_id) NOT LIKE '%cube%';
- Open cTables;
- Declare @table1_Scheme_Name sysname,
- @table1_Name sysname,
- @table2_Scheme_Name sysname,
- @table2_Name sysname;
- While 1 = 1
- Begin
- Fetch Next From cTables Into @table1_Scheme_Name, @table1_Name, @table2_Scheme_Name, @table2_Name;
- If @@FETCH_STATUS <> 0
- Break;
- PRINT Concat(@table1_Scheme_Name, '_', @table1_Name, ' -> ', @table2_Scheme_Name, '_', @table2_Name, ';');
- End;
- Close cTables;
- Deallocate cTables;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement