Exporting all SQL tables to txt file

  • I have a SQL 2005 database. I have almost 100 tables in that database. Now I would like to Make a csvor txt file for each table. How do I export each table to csv table. I know from the management studio you can do this but I think you can do this one by one. But how do i do this for all the 100 tables altogether. Any idea????

    Thank you.

  • espanolanthony (1/27/2011)


    I have a SQL 2005 database. I have almost 100 tables in that database. Now I would like to Make a csvor txt file for each table. How do I export each table to csv table. I know from the management studio you can do this but I think you can do this one by one. But how do i do this for all the 100 tables altogether. Any idea????

    Thank you.

    You can create a script that loops over all the tables and export them to flat files using the bcp utility.

    http://www.mssqltips.com/tip.asp?tip=1633

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Much simpler method would be to use Import\Export Wizard.

    Rt Click on a DB --> Tasks ---> Export data --> Select all the tables and specify an output text\csv file.

    Thank You,

    Best Regards,

    SQLBudy

  • No there's no option to select all the tables.

  • There's always PowerShell and ADO. Pretty easy that way.

    ----------------------------------------------------The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood... Theodore RooseveltThe Scary DBAAuthor of: SQL Server 2017 Query Performance Tuning, 5th Edition and SQL Server Execution Plans, 3rd EditionProduct Evangelist for Red Gate Software

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply