MS SQL Server 2008: How to export all the tables into CSV?

17,131

A more robust solution is to use the Oracle Migration Workbench. This used to be a separate utility from Oracle, but is now included in Oracle SQL Developer . If you and CLOB/BLOB data types then this is the way to go. You should also read the Oracle documentation on how to migrate as the SQL Developer migration interface is not very intuitive.

If you do want to go down the road of exporting all tables to csv you can use BCP or SSIS. There is a very good article on simple-talk on using some t-sql and to generate bcp export commands for all tables in a database. You can also create simple SSIS package to export all the tables to csv by using a flat file destination task.

here's something quick & dirty that will generate the BCP commands for you. Run it in SSMS, the run the output at the command prompt.

            USE AdventureWorks
SELECT 'bcp ' +
            QUOTENAME(DB_NAME())
            + '.'
            +QUOTENAME(SCHEMA_NAME(schema_id))
            + '.'
            +QUOTENAME(name)
            + ' '+'out'+' '
            + name + '.csv -w -t"|" -E -S '
            + @@servername
            + ' -T'
    FROM sys.objects
    WHERE TYPE='u'
        AND is_ms_shipped=0
Share:
17,131

Related videos on Youtube

Andrew
Author by

Andrew

Sceptic

Updated on September 17, 2022

Comments

  • Andrew
    Andrew over 1 year

    I have to migrate from MS SQL Server and now creating a new ORACLE database with the data partially got from my old tables.

    For that I need to get the data from dozens of tables as unicode CSV or TXT files, with fields separated by "|".

    The bad thing is the default export master of MS SQL Server can export only single table at a time, and it takes a considerable time to configure export options for each table. I started to export them manually but I got an attack of nerves at the 10th table.

    Do you know the way how to export ALL the tables into csv or txt from SQL server?

  • Andrew
    Andrew over 13 years
    I can't export all my tables this way, only 1 by 1. I have to pass "Tasks -> Export Data -> ... -> Flat file -> settings -> select single table for export" for each table. It's too damn big database, I need a bit faster solution.
  • Andrew
    Andrew over 13 years
    is it compatible with SQL Server 2008?
  • James
    James over 13 years
    Good question and it seems no is the answer however there may be workarounds <br> forums.oracle.com/forums/…
  • Andrew
    Andrew over 13 years
    Thanks for help, James. The script from Nick Kavadias works fine in BCP