Finding which columns contain data in a table

5 pts.
Tags:
columns
Data migration
Database migration
Oracle Database
SQL Database
I have to establish which columns in a table have data present. Each row has up to 100 columns, and not all of the columns contain data relating to the row. So in Table 1, Col1 Col2 Col3 Col4 Row 1 abc Row 2 abc Row 3 abc Would give a report showing that Table 1 has Columns Col1, Col2, Col4 being used. Application. We are moving from an Oracle database application to an SQL database application. The data migration mapping cannot be field for field, and I need to know that the data we actually have in the Oracle data set has a placeholder in the SQL data set before the exercise is started.

Answer Wiki

Thanks. We'll let you know when a new response is added.

The following query will give you that information for a specific table:

<pre> select column_name,data_type,data_length,data_precision,nullable,column_id
from all_tab_columns atc, all_tables at
where atc.table_name = at.table_name
and atc.owner = at.owner
and at.owner = ‘&owner’
and at.table_name = ‘&table’
and atc.num_nulls < at.num_rows
order by atc.column_id;</pre>

(I tested it on Oracle 8i, thereby I could not use the ANSI join syntax)

I think you can achieve the same without joining the all_tables table, this way:

<pre> select column_name,data_type,data_length,data_precision,nullable,column_id
from all_Tab_columns
where owner = ‘&owner’
and table_name = ‘&table’
and num_distinct != 0
order by column_id;</pre>

Please note that tables need to be analyzed in order to get accurate results.

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following