Tuesday, 19 June 2012

Creating Insert Query from An Existing Table in MSSQL

How To create an Insert Query from an existing table in MSSQL


These are the steps to create Insert query from an existing table in MSSQL. It will be helpful in importing the data from one db to another. I am using SQL Server 2008 R2.
The steps involved are:

  • Open your SQL SERVER Management Studio.
  • Select the database for which you want to create the queries.
  • Right Click on it and select Task. Under Task Select Generate Scripts.
insert query from existing table in mssql


  • It will open the Generate and Publish Script wizard.
How to generate insert query in mssql

  •  Click Next.
  • This will take us to Choose object screen, where we have choice to either generate script for the entire database or for few selected tables.
Creating Insert Query MSSQL

  • If you want to generate the query for a particular table, then select the "Select specific database objects" option. After that you can check the tables for which you want to generate the query.
  • Here I am creating the script for the entire database.
  • Click Next. This will open the screen in which we have to set the scripting options.

  •  In this screen select the advanced tab.  This will open the Advanced Scriptiing option. In this screen change the Types of data selected to "schema and data " if you want to have the table structure along with insert queries and "data only" if you want insert queries only.
creating insert query in mssql server management studio

  • Press Ok. And then click Next. You will see now "Review Your Selection" screen. Here you can re-check the options you have selected.  If everything is right select next.
creating insert query in mssql management studio

  • If Everything is correct then you will get the success screen. And you can check your file in the location were you have saved it.


Hope it helps someone who is learning the MSSQL like me.