How to Generate Database Scripts With Data In SQL Server

When migrating an MS SQL database between hosts or from your local development environment to your live hosted environment sometimes a .bak will not restore due to differing versions. In this case you will need to script the database schema and data and then run that script against the destination database. This article shows you how to generate database scripts with data in SQL Server.

1. Open up SQL Server Management Studio (SSMS) and connect to your database. Then right-click on your database and select Tasks -> Generate Scripts...

2. Click 'Next' on the Generate and Publish Scripts Wizard Introduction screen.

3. Click 'Next' to select all the objects in the database to be scripted or select the specific ones you need and then click 'Next'.

4. Click on the 'Advanced' button.

5. Scroll down and select 'Schema and Data' from the 'Types of data to script' dropdown. Update the name and location you want the script saved too.

6. Review your choices and then click 'Next'. Your script will now be generated and saved to the location specified. Click the 'Finish' button to close the wizard.

Return to Category