I am really new to Stackoverflow apologies for any mistakes.
I am working on Qlikview. It doesn't allow the columns which are of same name in two different tables. I used to create aliases for each and every column every time when i need to import tables from oracle. Now i want to deal with large database. So i decided to create a procedure that takes all the non constraint column as input and append there table name with column names.
I have written a sql query with basic knowledge that returns now primary columns but when coming to foreign keys doesn't work (it retrieving the columns which are having foreign keys)
My query is as follows
SELECT C.table_name,
C.column_name
FROM user_constraints a,
user_cons_columns b,
ALL_TAB_COLUMNS C
WHERE a.OWNER =b.owner
AND a.OWNER =C.owner
AND C.COLUMN_NAME !=b.COLUMN_NAME
AND a.CONSTRAINT_NAME =b.CONSTRAINT_NAME
AND a.table_name =b.table_name
AND a.table_name =C.table_name
AND a.constraint_type IN('P','R')
AND a.table_name NOT LIKE 'BIN%'
AND A.TABLE_NAME NOT LIKE 'DEF%'
AND b.table_name NOT LIKE 'BIN%'
AND b.TABLE_NAME NOT LIKE 'DEF%'
AND C.table_name NOT LIKE 'BIN%'
AND C.TABLE_NAME NOT LIKE 'DEF%';
Any suggestions will be appreciated
Thank you