Sql-server – How to generate an INSERT script for an existing SQL Server table that includes all stored rows

sql serverssms

I'm looking for a way to generate a "Create and insert all rows" script with SQL Management Studio 2008 R2.

I know that I can create a "create table" script.

I can also create an "insert in" script, but that will only generate a single row with placeholders.

Is there a way to generate an insert script that contains all currently stored rows?

Best Answer

Yes, but you'll need to run it at the database level.

Right-click the database in SSMS, select "Tasks", "Generate Scripts...". As you work through, you'll get to a "Scripting Options" section. Click on "Advanced", and in the list that pops up, where it says "Types of data to script", you've got the option to select Data and/or Schema.

Screen shot of Advanced Scripting Options