|
-
Well, I guess I figured it out. This:
SELECT A.TABLE_NAME, a.column_name,c.table_name "ref table",c.column_name "ref column"
FROM user_cons_columns a,user_cons_columns c,user_constraints b
WHERE a.constraint_name=b.constraint_name
AND a.table_name=b.table_name
AND (A.table_name=@TABLE_NAME)
AND b.constraint_type='R'
AND b.r_constraint_name=c.constraint_name;
gives me the results I wanted. That gets the parent tables for the foreign key. I also found that changing the (A.table_name = @TABLE_NAME) to (C.table_name = @TABLE_NAME) yields the child tables for the foreign key. The thing is, I don't really fully UNDERSTAND why this works. I came across the answer by perusing several different forums and eventually joining together a hodge podge of different answers into the above query which somehow gave me my answer. Mostly what I don't understand is why is it that table a and table c both reference user_cons_columns and yet a.column_name and c.column_name return different values?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|