HOW TO back up a database (schema and data) as a SQL Server script

Did you know, SQL Server 2008 Management Studio has an in-built option to generate a script that can help you restore an entire database alongwith the data? Compared to a .BAK file that can also be used to restore a database, a script lets you peek into the schema AND data (INSERT statements for rows within tables are automatically generated) before you restore it.

Unfortunately, this cool feature is hidden under layers of options and isn't easily discoverable unless a really discerning user points it out.


Steps to generate script:
1. Right click on a database name, choose Generate Scripts.. option under Tasks.. in the context menu
2. In the Generate and Publish Scripts wizard which appears choose the database object for which you want to generate a script
3. Under the Set Scripting Options, make sure to click on the Advanced button which reveals a bunch of more options.
4. In the new dialog box that opens up, scroll down to the last option in the General category and for Types of data to script, choose Schema and Data

If you need a migrate a database via a script for SQL Azure/SQL Database, you have to set the value for Script for the database engine type setting in the Advanced Scripting Options dialog box to SQL Azure Database


Related:
HOW TO view parameter values of a stored procedure through SQL Profiler
Why are these Visual Studio Settings not enabled by default?

Comments

Popular posts from this blog

Maven Crash Course - Learn Power Query, Power Pivot & DAX in 15 Minutes

"Data Prep & Exploratory Data Analysis" course by Maven Analytics

Oracle Cloud Infrastructure 2024 Generative AI Professional Course & Certification Exam (1Z0-1127-24)