1

Is there a way to generate an INSERT statement for the rows in an existing table?

I have a table in SQL Server 2008 with 150 rows. I am wondering if something like the following is possible to get from that table.

INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)
VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway'); 

The SQL script should include all the 150 rows to insert.

Yanov Adamsky
  • 122
  • 2
  • 9

1 Answers1

5

Here are the steps:-

  1. Right click on your database in SSMS
  2. Choose Tasks>Generate Scripts
  3. Select specific database objects - choose the table you want to script. Click next
  4. Select 'Save to new query window'. Click the 'Advanced button'
  5. Change 'Types of data to script' to 'Data only'.
  6. Click OK, Next, Next, Finish.

The query editor window should contain the script you need.

Mat Richardson
  • 3,576
  • 4
  • 31
  • 56