How to export SQL server database as a script file including the data

In the SQL Server 2008 is a less known possibility to export the whole database schema including all the data in the database as single script file.

To do this, start SQL Server Management Studio, select a database and right click on it and choose tasks and Generate Scripts menu item.

Now, you will get Generate Scripts wizard, skip the Introduction step and choose Script entire database and all database objects. Yes, you can also select some of them.

On the next step, you are on an important screen – Set Scripting options. Here you can specify how to publish or save your script. To export the data together with database schema, you have to choose Advanced button, which will take you to a screen for adjust the export options.

On the Advanced Scripting options you need to scroll down and find Types of data to script. Change the combobox to Schema and data. This will include also data (inserts) in your script.

When you close Advanced Scripting options, you can change also patch where your data will be scripted.

That’s all, you just need to confirm the Summary step and wait until operation finishes.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s