Sunday, March 25, 2012

Exporting DB as SQL using SQL Server 2005

Hi all,

I have a MSSQL database running on my SQL 2005 server and I want to export the entire contents to a file as SQL statements with INSERT statements. How do I do this?

I've discovered how to export the contents as a flat comma deliminiated file (although only one table at a time) and how to export the CREATE statements in SQL for each table but so far I cannot find a way to just export the entire DB as SQL.

Thanks!

There are no SQL Server tools that will create the INSERT statements for you...but it should be fairly staightforward to create a C# program that would gererate the CREATE TABLE statements using SMO and then code to retrieve the data for generating the INSERT statements.

Thanks,

Peter Saddow

|||

Hi,

tzake a look at this one here: http://vyaskn.tripod.com/code/generate_inserts_2005.txt

Just to give you an example SMO for creating table scripts (DDL) is quite easy, that a sample posted a few days ago:

string Script = new Microsoft.SqlServer.Management.Smo.Server(".").Databases["Adventureworks"].Tables["SomeTable"].Script();

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de

No comments:

Post a Comment