Friday, December 15, 2023

SQL Server How to generate INSERT query script from a table

In this post we will learn about generating INSERT statements from a table of SQL server database. We assume that the table is already populated. For each record of the table, INSERT statement will be generated.

We use the following steps to generate the script file for this.

  1. Login to the SQL Server using SSMS.
  2. Press F8 key to view the object Explorer.
  3. Right click the database in which table is existing.
  4. Select the Tasks menu item from the shortcut menu bar.
  5. Click Generate Scripts item from the sub menu bar.
  6. The Generate Scripts dialogue box Click the Next button.
  7. Now we get two radio buttons to ‘Select the database objects to script’. Select the second radio button i.e. Select Specific database objects. Expand the Tables node and check mark the table from which script is to be generated. Click the Next
  8. In the next window, we Set Scripting Options. Check mark the Save as script file radio button. Select Single script file. Change the file name in File name text box if required.

The following step is important to generate INSERT statements.

  1. Click the Advanced button and scroll down in the General section and select the Types of data to script. From the drop down select 'Schema and Data'
  2. Click the OK button. Now click the Next button. Again click the Next button. Click the Finish button.

Script will be generated. It will take some time. The script is generated in the file path given in File name.

Step by step screenshots are given below for hints.

Step1.



Step2.



Step3.



Step4.



Step5.



Step6.
Step7. Look into the target path where script file is generated.



In the next post we will learn about Tables in SQL Server.


No comments:

Post a Comment

Hot Topics