How to backup Sql Server to sql file?

若如初见. 提交于 2019-12-04 15:33:01

问题


In "Back UP" I only get a bak file, but I would like to create .sql file


回答1:


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.




回答2:


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.




回答3:


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:




回答4:


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




回答5:


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.




回答6:


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.




回答7:


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



来源:https://stackoverflow.com/questions/5212580/how-to-backup-sql-server-to-sql-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!