Sql-server – Script to generate insert statements

sql server

I am trying to write an SQL script to create an insert statement for each row of table TEST which has field A (int) and field B varchar(30), in my MS SQL database.

I would like to save those insert statements into a txt file to be able to apply that data back to another database.

Any idea about how to do it?

Best Answer

  1. Right-click on your Database in Object Explorer
  2. Select Tasks -> Generate Scripts...
  3. In that wizard you will be able to select the desired object(s) that you'd like to script out
  4. The next portion has an Advanced button, click that
  5. Under General, you will see the option called Types of data to script. The options are Schema only, Schema and data, or Data only. I believe you want the last option (Data Only)