Technical Article

Export all tables to CSV files

,

It generates sentences to export all database tables to a .csv file as this:

USE AdventureWorks
SELECT 'bcp ' + '"SELECT * FROM ' + 
            QUOTENAME(DB_NAME())
            + '.'
            +QUOTENAME(SCHEMA_NAME(schema_id))
            + '.'
            +QUOTENAME(name)
            + '"'+' queryout'+' '
            + 'c:\' + name + '.csv -c -t, -T -S '
            + @@servername
           
    FROM sys.objects
    WHERE TYPE='u'
        AND is_ms_shipped=0

Rate

3.5 (2)

You rated this post out of 5. Change rating

Share

Share

Rate

3.5 (2)

You rated this post out of 5. Change rating