Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. Declare cTables Cursor LOCAL FORWARD_ONLY FAST_FORWARD READ_ONLY For
  2. SELECT Distinct
  3. OBJECT_SCHEMA_NAME(fk.parent_object_id) AS Table1_Scheme_Name,
  4. OBJECT_NAME(fk.parent_object_id) AS Table1_Name,
  5. OBJECT_SCHEMA_NAME(fk.referenced_object_id) AS Table2_Scheme_Name,
  6. OBJECT_NAME (fk.referenced_object_id) AS Table2_Name
  7. FROM sys.foreign_keys fk
  8. INNER JOIN sys.foreign_key_columns AS fc ON fk.[OBJECT_ID] = fc.constraint_object_id
  9. where fk.parent_object_id <> fk.referenced_object_id AND
  10. OBJECT_SCHEMA_NAME(fk.parent_object_id) NOT IN ('sys', 'pm', 'alog', 'mnt') and
  11. OBJECT_SCHEMA_NAME(fk.referenced_object_id) NOT IN ('sys', 'pm', 'alog', 'mnt') AND
  12. OBJECT_NAME(fk.parent_object_id) NOT LIKE '%cube%' and
  13. OBJECT_NAME(fk.referenced_object_id) NOT LIKE '%cube%';
  14.  
  15.  
  16.  
  17. Open cTables;
  18.  
  19.  
  20.  
  21. Declare @table1_Scheme_Name sysname,
  22. @table1_Name sysname,
  23. @table2_Scheme_Name sysname,
  24. @table2_Name sysname;
  25.  
  26.  
  27.  
  28. While 1 = 1
  29. Begin
  30. Fetch Next From cTables Into @table1_Scheme_Name, @table1_Name, @table2_Scheme_Name, @table2_Name;
  31. If @@FETCH_STATUS <> 0
  32. Break;
  33.  
  34.  
  35.  
  36. PRINT Concat(@table1_Scheme_Name, '_', @table1_Name, ' -> ', @table2_Scheme_Name, '_', @table2_Name, ';');
  37. End;
  38.  
  39.  
  40.  
  41. Close cTables;
  42. Deallocate cTables;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement