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.
Firstly, Open Microsoft SQL Server Management Studio and decide from which existing database (DBEmployee) you want to generate database scripts.
Now, right-click on your database name (DBEmployee). Then select Tasks option and click on the Generate Scripts… option.
Now, ‘Introduction‘ dialogue box will open. Click on the Next > button.
Now, ‘Choose Objects‘ dialogue box will open. Select Script entire database and all database objects and then click on the Next > button.
Now, ‘Set Scripting Options‘ dialogue box will open. Click on the Advanced button.
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.
Click on the Next > button. Now, ‘Summary‘ dialogue box will open and then click on the Next > button.
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