简体   繁体   English

使用脚本或cmd将SQL SERVER备份数据库转换为.sql文件

[英]SQL SERVER backup database into .sql file using script or cmd

I am trying to migrate from SQL SERVER 2012 to 2014 and found out I cannot use .bak files because of different versions. 我正在尝试从SQL SERVER 2012迁移到2014,发现由于版本不同,我无法使用.bak文件。 I know how to create a .sql back up file using the SSMS but I can't find a solution using a script or sqlcmd. 我知道如何使用SSMS创建.sql备份文件,但找不到使用脚本或sqlcmd的解决方案。

turns out I could use .bak files to restore databases. 原来我可以使用.bak文件还原数据库。 The problem was I'm trying to restore the file from a directory that SSMS is not authorized. 问题是我试图从未经授权的SSMS目录中还原文件。 Was a silly mistake. 是一个愚蠢的错误。 Sorry. 抱歉。

If you require to get the data in .sql files then the SQL Server's Generate Scripts wizard is the best option otherwise you can create .bak of your database and restore it on higher version. 如果需要获取.sql文件中的数据,则SQL Server的“生成脚本”向导是最佳选择,否则,您可以创建数据库的.bak并将其还原到更高版本。

在此处输入图片说明

Why can't you use SSMS? 为什么不能使用SSMS?

Exporting to .sql file has been discussed in How to backup Sql Server to sql file? 如何将Sql Server备份到sql文件中已讨论了导出到.sql 文件?

Did you consider Linked Servers ? 您是否考虑过链接服务器 You can use 3 and 4 part names to access data from one server to another, for details see How can I connect to an external database from a sql statement or a stored procedure? 您可以使用3和4部件名称来将数据从一台服务器访问到另一台服务器,有关详细信息,请参见如何从sql语句或存储过程连接到外部数据库? . Another alternative to access data is trough OPENROWSET, that is also discussed above. 访问数据的另一种方法是通过OPENROWSET,这也在上面讨论过。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM