Generate table Insert script in sql server

Asked

Viewed 8,878 times

3

Using Sql Server 2012. I made a query with the title above and did not bring anything in the search. I have a BD and need to take it elsewhere. Therefore, the best way is to generate a script of all the existing objects in it and as I have populated tables, I also need to generate a script of insert. How do I do it, the script of insert?

  • I recommend using a migration tool that will do quickly and without error. I’ve used this for Mysql, but it has an option for SQL Server as well. https://www.toadworld.com/products/toad-for-sql-server

  • You need your backup to be one script with instructions from insert into? Or it could be a normal backup file?

  • So I have a client that I was with and I needed data from his comic book so I could test an app that I developed. The guy in a few minutes, using Sql Management generated the DDL and DML scripts. Fast and could not keep track to see how it does. I tried to talk to him now and he is not in the unit, he is traveling and visiting the branches (south of São Paulo). I know it is, but I don’t know how. I’m searching the net, but so far I haven’t found it. I’ll go to Soen and see if I can find it there.

  • 1

    Check it out: https://stackoverflow.com/questions/4526461/converting-select-results-into-insert-script

  • 1

    Take a look at this question as well: https://answall.com/questions/232312/asposso-insert m%C3%Baltiplos-lines-once-s%C3%B3-using-sql/232320#232320

  • 1

    You can do this inside Management Studio, the problem is that it gets very slow when the database has a lot of data, the ideal is to generate a normal backup file, is faster and has no error.

  • It’s my bank. It only has 10 tables and only 3 are populated. I’m starting now to develop and need to migrate. I might start all over again, but I’d like to learn how to do that.

  • If you want to create only Inserts for an existing table, just use Data Only, and you don’t need to use Schema and Data. So the script gets cleaner. I use to migrate homologation data to production.

Show 3 more comments

1 answer

7


Enter Management Studio and right-click on the bank to be exported.

Access Tasks > Generate Scripts as per image

inserir a descrição da imagem aqui

Will open a Wizard. You choose the type of data you want to export (tables, views, functions...) and advance.

In the second step you click "advanced" and change the item "type of data to script" to "schema and data", otherwise the script will generate the database structure but will not insert the data! View image

inserir a descrição da imagem aqui

Now just go giving next on Wizard and it will generate the file in your "Documents" folder (or the place you select).

  • I had to choose the type of data, which by default appears only Schema, but is Schema and Data.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.