Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I generate insert statements with Sql server 2012? [duplicate]

I have sql server 2012 express and just installed the latest version of ssms tools from http://www.ssmstoolspack.com/Download

With sql server 2008 express and ssms tools I was able to right click on a table and see an ssms tools option that allowed me to generate insert statements for a table but now I don't see it? Anyone know how I can generate the insert statements for a table?

like image 378
Eric Avatar asked Nov 07 '12 15:11

Eric


People also ask

How will you generate insert statements with data in SQL Server?

Steps To Auto Generate INSERT StatementsFrom the right-click menu, go to Tasks >> Generate Scripts... In the Generate and Publish Scripts pop-up window, press Next to choose objects screen. Now, the choose objects screen, choose Select specific database objects and choose the tables you want to script.

How will you generate insert script from select query in SQL Server?

Right click on the database > Tasks > Generate Scripts. Next. Select "Select specific database objects" and check the table you want scripted, Next. Click Advanced > in the list of options, scroll down to the bottom and look for the "Types of data to script" and change it to "Data Only" > OK.


1 Answers

You can script data natively with SSMS 2012 without using plugins such as SSMS Tools Pack, although the functionality is hidden away.

  • Right click on your database and select Tasks -> Generate Scripts
  • Click Next to move past the intro screen and onto the next page, then select the objects you want to script. Note that you can script all SQL objects here, not just tables. This is because this wizard allows you to script schema and data. Importantly, schema only is the default, which you'll need to change on the next page. Click Next.
  • Now you'll be presented with a set of options mainly relating to how the script is going to be output, however there is an unassuming button labelled Advanced. Clicking this button will give you a dialog with a list of options. The last option under the General section is "Types of data to script", which you should change from "Schema only" to "Data only", or "Schema and data".
  • Finally, decide where you want the script to do and you should be able to generate your INSERT statements.

See this blog post for more details, which is where I found out about this feature: http://raresql.com/2012/09/30/generating-insert-statements-in-sql-server-2012/

Note that unlike SSMS Tools Pack, this will generate an INSERT statement for every single row you are trying to script. If you have a large number of rows that you need to move around then you may want to pursue alternatives. However, for scripting small configuration tables this is perfect.

like image 143
StuartQ Avatar answered Oct 11 '22 00:10

StuartQ