Introduction
A script is created for all the tables, views, functions, stored procedures, indexes, and other objects of a chosen database when you do generate script actions. When backup failed to restore a database from a lower version database to an upper version due to different versions, it might be helpful in such a situation. In this situation, you can create a script using the database schema and data using generate scripts, then run that script against the target database. It can also be helpful if you only require one table's worth of data. You can script just one table's worth of data using the produce scripts option. Let's look at how to create a script for a whole database or just a few particular database objects.
The steps are as follows,
Step 1
Open SQL Server open your object explorer select the database
Step 2
Right-click on Database select the Tasks option
Step 3
Right-click on Task and select generate Scripts
Step 4
Press the next button to continue the process
Step 5
Firstly select save as script file and then click on the advanced option
Step 6
Now there is an option to select Types of Data to script which contains three options - Schema only, Data only, and Schema and Data choice depending on requirements. Currently, I am choosing Schema and Data and clicking the ok button
Step 7
After selecting save as script file, click on the first option to save the file.
Step 8
We have to provide the script file name and click on the save button.
Step 9
Now after all the steps, we move forward and click on the next button
Step 10
Again click on the next button
Step 11
In this final step save and generate the script
Conclusion
As you can see the scripts are extracted from SimpleAppTwoFactorAuthDb database. Accordingly, when you run this script, a database with the name SimpleAppTwoFactorAuthDb and all of its associated data will be generated.
If you have any queries/suggestions on the article, please leave your questions and thoughts in the comment section below. Follow C# Corner to learn more new and amazing things about SQL Server or to explore more technologies.
Thanks for reading and I hope you like it.