List all columns having only nulls from all tables in a database.

I want to select columns from all tables having only null values. Each table has 60+ columns and i have 100+ tables in database. Requesting a script to list all tables at a time and their columns having all nulls? Below is my expected output. Thank
you in advance !
Table name
Null valued Column
Address
Address Line 2
Address
Address Line 3
Address
Zip Code
Product
Product Desc
Product
Product SKU

Hello,
In addition to Naomi's reply, you can refer to the following links about loop through all the tables in the database:
http://www.codeproject.com/Tips/161663/Loop-through-all-tables-in-SQL-Server
http://social.msdn.microsoft.com/Forums/sqlserver/en-US/07b9799e-aeab-442e-99a0-ba76ab051f59/looping-through-databases-and-count-the-number-of-items-in-a-specific-table?forum=transactsql
Regards,
Fanny Liu
Fanny Liu
TechNet Community Support

Similar Messages

  • Insert into all tables on a Database on Test Server select from all tables on a database A from production server

     
    hi Friends ,i need a suggestion from  you on how to
    insert data to all tables on a Database  "A " on Test server
    Select data from all tables on  a Database  "A" on Production Server
    where id=123
    Database A is same with Structures on Test and Production also all Tables  will have  Id column in common.
    The purpose of this insert is ,as we all know Production has the latest data and i need to push to test server on request for particular ID only  ( may be weekly once or  twice a week )
    I  have a linked server setup name "LINQ" 
    Example for one table is below , like wise i need a script which does for 154 tables.
    Insert into ABC( id, name)---insert to test server
    Select Id, name  from  LINQ.ProdSerevrname.databasename.ABC where id = 123
    Please help me ..
    Thanks

    Why not use export import wizard for this if you've read access to production?
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Need a query to list all table names

    I have more than 500 tables in my database.
    'insert_date' & 'update_date' columns are found in more than 100 tables with data type as date.
    I need a query to list all table names and 'insert_date' , 'update_date' column's content.
    Please Help
    Lee1212
    Message was edited by:
    LEE1212

    I have more than 500 tables in my database.
    'insert_date' & update_date column is found in more
    than 100 tables with data type as date.
    I need a query to list all table names and
    'insert_date' column's content.What do you mean by "column's content". A table can have many rows. Do you want to display all the distinct value for these columns?
    Below is the query to get the tables which has columns insert_Date and update_date
    select table_name
    from user_tab_columns
    where column_name ='INSERT_DATE'
    or column_name ='UPDATE_DATE'
    /You can write a PL/SQL block to retrive the distinct values of INSERT_DATE for these tables
    declare
    TYPE ref_cur IS REF CURSOR;
    insert_date_cur ref_cur;
    lv_insert_date DATE;
    cursor tables_list IS
    select table_name
    from user_tab_columns
    where column_name ='INSERT_DATE';
    begin
    for cur_tables in tables_list
    loop
      OPEN insert_date_cur for 'SELECT DISTINCT insert_date from '||cur_tables.table_name;
      DBMS_OUTPUT.PUT_LINE(cur_tables.table_name);
      DBMS_OUTPUT.PUT_LINE('--------------------------------');
      LOOP
      FETCH insert_date_cur into lv_insert_date;
      EXIT WHEN insert_date_cur%NOTFOUND;
      DBMS_OUTPUT.PUT_LINE(lv_insert_date);
      END LOOP;
    CLOSE insert_date_cur;
    end loop;
    end;I haven't tested this code. There might be some errors. Just posted something to start with for you.

  • Newbie ques : How to get the list of all tables in the database

    Hi,
    I'm very new to Oracle (using Oracle8i currently). I wanted to know if there is a way to get the list of all tables in the database. Like in mySQL you can use the command " show tables" to get the list of all the tables.
    Any help will e greatly appreciated. Please "cc" any reply to [email protected] also.
    thanks
    Deven

    Hi
    Select table_name, owner from all_tables;
    will give u all the tables in the database.
    all_tables, dba_tables, user_tables
    all_objects, dba_objects, dba_objects
    there are many, more tables. login as system and query the tab and try to describe the tables.
    Thanks
    Malar

  • How to search all columns of all tables in a database

    i need to search all columns of all tables in a database , i already write the code below , but i've got the error message below when run this script
    DECLARE
    cnt number;
    v_data VARCHAR2(20);
    BEGIN
    v_data :='5C4CA98EAC4C';
    FOR t1 IN (SELECT table_name, column_name FROM all_tab_cols where owner='admin' and DATA_TYPE='VARCHAR2') LOOP
    EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ' ||t1.table_name|| ' WHERE ' ||t1.column_name || ' = :1' INTO cnt USING v_data;
    IF cnt > 0 THEN
    dbms_output.put_line( t1.table_name ||' '||t1.column_name||' '||cnt );
    END IF;
    END LOOP;
    END;
    Error report:
    ORA-00933: SQL command not properly ended
    ORA-06512: at line 7
    00933. 00000 - "SQL command not properly ended"
    *Cause:   
    *Action:
    Any help please

    SQL solutions by Michaels
    michaels>  var val varchar2(5)
    michaels>  exec :val := 'as'
    PL/SQL procedure successfully completed.
    michaels>  select distinct substr (:val, 1, 11) "Searchword",
                    substr (table_name, 1, 14) "Table",
                    substr (t.column_value.getstringval (), 1, 50) "Column/Value"
               from cols,
                    table
                       (xmlsequence
                           (dbms_xmlgen.getxmltype ('select ' || column_name
                                                    || ' from ' || table_name
                                                    || ' where upper('
                                                    || column_name
                                                    || ') like upper(''%' || :val
                                                    || '%'')'
                                                   ).extract ('ROWSET/ROW/*')
                       ) t
    --        where table_name in ('EMPLOYEES', 'JOB_HISTORY', 'DEPARTMENTS')
           order by "Table"or
    11g upwards
    SQL> select table_name,
           column_name,
           :search_string search_string,
           result
      from (select column_name,
                   table_name,
                   'ora:view("' || table_name || '")/ROW/' || column_name || '[ora:contains(text(),"%' || :search_string || '%") > 0]' str
              from cols
             where table_name in ('EMP', 'DEPT')),
           xmltable (str columns result varchar2(10) path '.')
    TABLE_NAME                     COLUMN_NAME                    SEARCH_STRING                    RESULT   
    DEPT                           DNAME                          es                               RESEARCH 
    EMP                            ENAME                          es                               JAMES    
    EMP                            JOB                            es                               SALESMAN 
    EMP                            JOB                            es                               SALESMAN 
    4 rows selected.

  • How do I run sp_spaceused for all tables in a database?

    Hi,
    I am struggling to understand how to run the sp_spaceused sproc for all tables in a database.
    I know how to use it for one table but how would I replicate it automatically for each table in a given database?
    Regards,
    Ian.

    I just managed to alter the code of VidyaSagar and have pulled out all the information including Schema name. Below is what it looks like:
    set
    nocount
    on
    select
    'Database Name: ',
    db_name
    if
    exists(select
    name from tempdb..sysobjects
    where name='##tmp'
    drop
    table ##tmp
    create
    table ##tmp(TABLE_SCHEMA
    nvarchar(256),TABLE_NAME
    nvarchar(256),
    num_rows int,
    reserved_KB varchar(15),data_KB
    varchar(15),index_KB
    varchar(15),unsed_KB
    varchar(15
    go
    declare
    @tbl_schema nvarchar(256
    declare
    @tbl_name nvarchar(256
    declare
    @schema_tbl_name nvarchar(256
    declare
    tblname CURSOR
    for
    select
    TABLE_SCHEMA
    TABLE_NAME
    from
    INFORMATION_SCHEMA.TABLES
    where TABLE_TYPE='BASE
    TABLE' 
    open
    tblname
    Fetch
    next
    from tblname
    INTO @tbl_schema,@tbl_name
    WHILE
    @@FETCH_STATUS
    = 0
    BEGIN
    set @schema_tbl_name=@tbl_schema+'.'+@tbl_name
    insert
    into ##tmp(TABLE_NAME
    , num_rows
    , reserved_KB
    ,data_KB
    ,index_KB
    ,unsed_KB
    exec
    sp_spaceused
    @schema_tbl_name
    update ##tmp
    set TABLE_SCHEMA
    =@tbl_schema
    where TABLE_SCHEMA
    is
    NULL
    and TABLE_NAME=@tbl_name
    FETCH
    NEXT
    FROM tblname
    INTO @tbl_schema,@tbl_name 
    END
    CLOSE
    tblname
    deallocate
    tblname
    go
    select
    from
    ##tmp
    drop
    table ##tmp
    Warm Regards, Ajay

  • Finding all tables of a database

    hi,
    i want to find out all table of a database .
    how could i.
    thnx

    try this
    DatabaseMetaData dbmd=con.getMetaData();
    ResultSet rsTable=dbmd.getTables(null,null,"%",null);
    while (rsTable.next())
    //String tableCatalog = rsTable.getString(1);
    //String tableSchema = rsTable.getString(2);
    System.out.println("Table Name - "+rsTable.getString(3)+" - catalog  - "+rsTable.getString(1)+" - schema - "+rsTable.getString(2)+" - Type - "+rsTable.getString(4));
    rsTable.close();

  • How to view all table of a database

    How to view all table of a database created on a oracle 9.2/10g database management system.
    How to view available tables of oracle dbms which comes by default with package.
    Thank you so much in advance!
    With Regards,
    Niks

    You posted the same question twice.
    How to view all table of a database

  • Delete a record from a table in a Database with Database Connectivity

    I can't find the function from the Database Connectivity library that allows me to delete a record from a table of the database. I tried to use DB Tools Free Object.vi function but this one deletes only the table created with a query.
    Thankyou

    I have used the sql query as described above and it works fine with access DB and the DB toolkit, the free object vi only deallocated a recordset's references this will noty alter the database since the record is a copy of the databases information.  The SQL delete function is very versatile and you should be able to delete records with no problem.
    Paul
    Paul Falkenstein
    Coleman Technologies Inc.
    CLA, CPI, AIA-Vision
    Labview 4.0- 2013, RT, Vision, FPGA

  • I need to copy data from a table in one database (db1) to another table in

    Hi
    I need to copy data from a table in one database (db1) to another table in another database (db2).
    I am not sure if the table exists in db2,,,if it doesnot it needs to be created as well data also needs to be inserted...
    How am I supposed to this using sql statements..?
    I shall be happy if it is explained SQL also...
    Thanking in advance

    How many rows does the table contains? There are manyway you can achieve this.
    1. export and import.
    2. create a dblink between two databases and use create table as select, if structure doesnot exists in other database, if structure exists, use, insert into table select command.
    example:
    create a dblink in db2 database for db1 database.
    create table table1 as select * from table1@db1 -- when there is no structure present
    -- you need to add constraints manually, if any exists.
    insert into table1 select * from table1@db1 -- when there is structure present.
    If the table contains large volume of data, I would suggest you to use export and import.
    Jaffar

  • Finding Columns with only NULL as values

    I have a list of tables around 30 in number. Among them i need to generate a report with Table Name and Column Names, for which all values are NULL.
    In other words, i need to find all the columns for which all the values are NULL.
    I thought of dealing it with cursors, and comparing the total count with null count in each column. But i need to loop "Number of columns" times. Is there any better way to do this?

    I think your way is a good solution. It has the advantage that you can check several columns in one select.
    select count(*), count(col1), count(col2) ... from mytabAnother approach could be to check statistical information about your table data.
    However this will not give you always the correct data.
    It depends on the time of the last statistic collection, the sample size and on the detail level.
    Here is a sample statement to play with:
    select owner, table_name, column_name, num_distinct, num_nulls, num_buckets, sample_size, low_value, high_value
    from all_tab_columns
    where owner not in ('SYS','SYSTEM')
    and nullable = 'Y' -- null values allowed
    and num_distinct = 0 -- only nulls found
    --and density = 0
    ;Note that this select would not return tables for which no statistics had been calculated. Num_distinct is NULL in such a case.
    Edited by: Sven W. on Feb 11, 2010 2:50 PM

  • One of the Column returned as NULL from SQL Server 2008

    Hi,
    I have written a stored procedure in SQL server 2008. The procedure reads data into a temporary table @MeterWiseConsumptionBetwDates as shown
    SELECT @sqlstatement =     'SELECT '''@MeterName''', CAST ( MAX('@Meterfield') AS FLOAT )-CAST ( MIN('@Meterfield') AS FLOAT )
                                  FROM KWH
                                  WHERE     KWH.timestamp BETWEEN @StDate AND @EndDate'
    INSERT INTO @MeterWiseConsumptionBetwDates(MeterName,Consumption)
    EXEC sp_executesql @sqlstatement, N'@StDate datetime, @EndDate datetime', @StDate, @EndDate
    Now when I execute the stored procedure in SQL Server Management Studio it returns all the columns from the table @MeterWiseConsumptionBetwDates, but when I execute the procedure in MII it returns the values in the Consumption column as null. The MeterName column is returned correctly in both the cases.
    Please help.
    Thanks

    Glad to hear that it is working.  You should be able to use
    execute <proc name> '[SD]'
    [SD] and [ED]
    are the query date tokens, so whatever you have assigned on the Date Range tab will be passed to the query.
    Jamie
    Edited by: Jamie Cawley on May 9, 2011 9:40 AM

  • How to search all columns of all tables in a database for a keyword?

    Dear Team,
    i have an requirement that : i want to search all the columns of all the tables in the particular database based on the specific key word or an free text.
    example :
    table 1: columns data
    empname sam
    empid 01
    table 2 columns data
    deptname sam
    departmentid 10
    table 3 columns data
    organization name sam
    organization id 1
    when i search for text " SAM"
    it should search me from the entire database, all tables and columns of it and display the result
    output : tablename cloumn value
    table1 empname sam
    table2 deptname sam
    table3 organizationame sam
    the example is just an sample not the real data .
    please help me with sample code or any link related to it .
    thanks in advance

    Hi justin , thanx for the reply
    the basic requirement that we required is ,
    the user will just type the keyword( value in the coumn) he required and it should search all the tables and columns of the table in the database and i have to show this in the front ent in the table format. here the user will analyse the information based on the search .
    it is just like the google search we does( type the keyword in free text) it will display the result.
    so for that i have to search entire table and columns in the whole database.
    please if any one provides me the solution it will be help full for me.
    thanx in advance

  • List All Tables in a Microsoft Access Database

    Hello,
    I am writing in a Java code. This code analyze a Microsft Access Database file and then print a report about it.
    The connectivity between Java and the Database is fine, but My problem is that I want to display ALL Table names of the Database:
    For example: if the database is save in a file Data.mdb and if the database contain tables: Customer, Employee, Sales. I want a way to get those names!. I tried to excute a query "Desc Data" but it gave me SQL error sayas that you are allowed to use Select, Insert, Delete and Update keyword only.
    Any HELP?

    you can do it the following way...
    using your Connection obj (say connection)
    DatabaseMetaData dm = connection.getMetaData();
    ResultSet rs = dm.getCatalogs();
    String cat = null;
    if(rs.next())
    cat = rs.getString("TABLE_CAT");
    String[] str = new String{}["TABLE"]
    rs = dm.getTables(cat,null,null,str);
    while(rst.next())
    System.out.println("Tables"+rs.getString("TABLE_NAME"));
    kind regards
    Oliver

  • How to list all  tables that belongs to the current user?

    hi all
    "select tblowner,tblname from tables where tblowner in (select user from dual);"
    I want a list of all tables that belongs to the current user. I use the SQL above, but given "no rows selectd",but if
    I replace the subquery with literal,like
    "select tblowner,tblname from tables where tblowner = 'JFMDB');".
    I got the list. why?
    Thnk u very much!

    This looks like a bug that was fixed in 7.0.5.13 and onwards. I can reproduce what you are seeing in 7.0.5.10.0 (Linux x86-64 / Access control enabled instance from root install) but not 7.0.5.13.0 (Linux x86-64 / Access control enabled instance from root install).
    Unfortunately I don't have a bug number to pass on. I can't see anything relevant listed in the Release Notes and I haven't found a likely candidate in our internal listings. This may well have been one that was fixed "in passing" when RnD were working on something similar.

Maybe you are looking for