How to backup Sql Server to sql file? – Stack Overflow

apple-touch-icon@2In “Back UP” I only get a bak file, but I would like to create .sql file

Sorgente: How to backup Sql Server to sql file? – Stack Overflow

I may need it pretty soon

Use SQL Server’s Generate Scripts commend

  • right click on the database; Tasks -> Generate Scripts
  • select your tables, click Next
  • click the Advanced button
  • find Types of data to script – choose Schema and Data.
  • you can then choose to save to file, or put in new query window.
  • results in CREATE and INSERT statements for all table data selected in bullet 2.

shareimprove this answer

This is a possible duplicate of: SQL script to get table content as “SELECT * FROM tblname”

To do a full database backup to File/Query you can use the ‘Generate Scripts…’ option on the Database.

Open SQL Server Management studio, right click on the database and choose ‘Tasks->Generate Scripts…’

Then use the wizard to backup the database. You can script the whole database or parts of it. Two important options: In the ‘Advanced’ section, you will probably want to ensure ‘Type of backup = ‘Schema and Data’ and the ‘Script Statistics’ is on.

This will produce a *.sql file that you can use as a backup that includes the schema and table data.

shareimprove this answer
1
it does not generate inserts 🙁 – IAdapter Mar 14 ’11 at 8:16
4
You need to ensure that ‘Type of Backup = Schema and Data’. It definately generates INSERT statements when you have selected this also. – Simon Mar 15 ’11 at 3:07
1
Specifically while on the “Set Scripting Options” step of the wizard you need to click “Advanced” to the right of the “Save to file”. Then under “Types of data to script” choose “Schema and data” – Jason Axelson Feb 20 ’13 at 2:42

Ok, I read through most of these, but I had no “advanced button”. But, there is still a way to do it, it’s just a little hard to find, so here you go:

shareimprove this answer

You can generate a script from a database, see http://msdn.microsoft.com/en-us/library/ms178078.aspx

shareimprove this answer
it does not generate inserts 🙁 – IAdapter Mar 14 ’11 at 8:16

If you want to create a script of your database you right-click on the databases and Generate Scripts (it’s in different sub-menus depending on what version of SQL and Enterprise Manager / SQL Server Management studio you’re using).

That will, however, only get you the database objects. It will not generate scripts for data. Backing up a database will give you all of the database objects as well as the data, depending on what recovery model your database is set to.

shareimprove this answer

This fellow may have achieved what you are trying to do by creating the backup, and then restoring it and giving it a new name.

This approach copies the data along with all of the database objects.

shareimprove this answer

If you want a file with insert statements for your data have a look here:

This procedure generates INSERT statements using existing data from the given tables and views. Later, you can use these INSERT statements to generate the data. It’s very useful when you have to ship or package a database application. This procedure also comes in handy when you have to send sample data to your vendor or technical support provider for troubleshooting purposes.

http://vyaskn.tripod.com/code.htm#inserts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.