In this article, we will learn how we can generate a script(s) of our database with existing data, in SQL Server.
Once database script(s) are generated, the result will give you an insert query with other queries so that the data also will get inserted in your new database.
Now, let’s follow the below steps to generate database script(s) with data in SQL Server.
Step 1:
Firstly, Open Microsoft SQL Server Management Studio and decide from which existing database (DBEmployee) you want to generate database scripts.
Step 2:
Now, right-click on your database name (DBEmployee). Then select Tasks option and click on the Generate Scripts… option.
Step 3:
Now, ‘Introduction‘ dialogue box will open. Click on the Next > button.
Step 4:
Now, ‘Choose Objects‘ dialogue box will open. Select Script entire database and all database objects and then click on the Next > button.
Step 5:
Now, ‘Set Scripting Options‘ dialogue box will open. Click on the Advanced button.
Step 6:
Now, ‘Advanced Scripting Options‘ dialogue box will open. Choose Schema and data from the Types of data to script drop-down list and then click on the OK button.
Step 7:
Click on the Next > button. Now, ‘Summary‘ dialogue box will open and then click on the Next > button.
Step 8:
Click on the Finish button.
Thus, we have learned to generate script(s) of our database with existing data in SQL.
Now check the script file (C:\Users\PC-NAME\Documents\script.sql), it must be having the insert queries too.
Also, check How To Export Excel In SQL Table