1

Suppose I have a table with data like:

Tab(id, name)
1, 'Name 1'
2, 'Name 2'
3, 'Name 3'

In SQL Server management studio, I can generate script to create this table(ddl). But I also want generate sql for data like:

insert into Tab(id, name) values(1, 'Name 1');
insert into Tab(id, name) values(2, 'Name 2');
insert into Tab(id, name) values(3, 'Name 3');

How to generate above insert sql with data for a table?

KentZhou
  • 24,805
  • 41
  • 134
  • 200
  • 1
    Check this out http://stackoverflow.com/questions/982568/what-is-the-best-way-to-auto-generate-insert-statements-for-a-sql-server-table – Bala Oct 14 '11 at 19:00
  • what is your use case? You can use bcp utilities if you have to copy to some other table. – Bala Oct 14 '11 at 19:01

2 Answers2

2

Under Tasks > Generate scripts you can hit 'Advanced'

One of the choices is "Types of Data to Script" which is set by default as Schema only.

Go for "Data and Schema" and that's it.

Haedrian
  • 4,240
  • 2
  • 32
  • 53
0

This will help: http://sqlblog.com/blogs/eric_johnson/archive/2010/03/08/script-data-in-sql-server-2008.aspx

Ion Sapoval
  • 635
  • 5
  • 8
  • 1
    While this may theoretically answer the question, [it would be preferable](http://meta.stackexchange.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – Bill the Lizard Oct 14 '11 at 19:14