Guest User

Untitled

a guest
Jun 22nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. select constraint_name
  2. from dba_constraints
  3. where owner = '<SCHEMA_NAME>' and table_name = 'STUDENT' and constraint_type = 'P';
  4.  
  5. select owner, table_name, constraint_name
  6. from dba_constraints
  7. where r_constraint_name = '<result from previous query>' and constraint_type = 'R';
  8.  
  9. select owner, table_name, column_name
  10. from dba_cons_columns
  11. where constraint_name = '<constraint name from previous query>';
  12.  
  13. SELECT fk.owner, fk.table_name, col.column_name
  14. FROM dba_constraints pk
  15. JOIN dba_constraints fk
  16. ON pk.constraint_name = fk.r_constraint_name
  17. AND fk.constraint_type = 'R'
  18. JOIN dba_cons_columns col
  19. ON fk.constraint_name = col.constraint_name
  20. WHERE pk.owner = :owner AND pk.table_name = 'STUDENT' AND pk.constraint_type = 'P';
  21.  
  22. SELECT *
  23. FROM sys.all_constraints a
  24. INNER JOIN sys.all_constraints b
  25. ON a.constraint_name = b.constraint_name
  26. INNER JOIN sys.all_cons_columns c
  27. on c.constraint_name = b.constraint_name
  28. WHERE a.constraint_type = 'P'
  29. AND b.constraint_type = 'R'
  30.  
  31. select fk.table_name, col.column_name
  32. from USER_constraints fk
  33. JOIN user_cons_columns col
  34. ON fk.constraint_name = col.constraint_name
  35. where constraint_type='R'
  36. and r_constraint_name in (
  37. select constraint_name
  38. from user_constraints
  39. where constraint_type in ('P','U')
  40. and table_name='TABLE_NAME'
  41. );
Add Comment
Please, Sign In to add comment