简体   繁体   English

复制完整的SQL Server 2008数据库

[英]Copy complete SQL Server 2008 db

In order to deploy my application I would like to copy db schema and content from my devel maschine to a production server. 为了部署我的应用程序,我想将数据库架构和内容从开发机器复制到生产服务器。 Even better, I'd like to be able to regularly communicate changes in the devel db to the production db by completely resetting the production db to an exact copy of the devel machine. 更好的是,我希望能够通过将生产数据库完全重置为开发机器的精确副本,来定期将开发数据库中的更改传达给生产数据库。

With mysql this would be easily accomplished by dumping the prod db to a file and loading the dump into the target db. 使用mysql,可以通过将prod db转储到文件并将转储加载到目标db中来轻松实现。 Unfortunately, I couldn't find similar functionality on my SQL Server (Express). 不幸的是,我在SQL Server(Express)上找不到类似的功能。 The import/export functions I have been finding either only concern the schema, not the data, or they work on one table at the time, meaning that they don't copy relationships between tables. 我发现的导入/导出功能要么只涉及架构,不涉及数据,要么它们仅在一个表上工作,这意味着它们不复制表之间的关系。

Copying a complete db would seem like a common problem so I hope there is a solution out there. 复制完整的数据库似乎是一个常见问题,因此我希望那里有解决方案。 Any advice? 有什么建议吗?

Cheers, Duffy 干杯,达菲

For a simple way of copying a database in sql server you will need to do backup and restore. 对于在sql server中复制数据库的简单方法,您将需要进行备份和还原。

3 Steps: 3个步骤:

1.)Steps on how to backup the database http://msdn.microsoft.com/en-us/library/ms187510.aspx 1.)有关如何备份数据库的步骤http://msdn.microsoft.com/zh-cn/library/ms187510.aspx

2.) In target server create a new database. 2.)在目标服务器中创建一个新数据库。

3.) Restore database. 3.)恢复数据库。 Right click on the newly created database and follow these steps... http://msdn.microsoft.com/en-us/library/ms177429.aspx 右键单击新创建的数据库,然后按照以下步骤操作: http://msdn.microsoft.com/zh-cn/library/ms177429.aspx

And you are done! 您完成了!

If you want a real-time synchronization, you might wanna try replication... :) 如果您想进行实时同步,则可以尝试复制... :)

Try reading this thorough documentation of replication. 尝试阅读此详尽的复制文档。 Check this out this will surely help you :) 检查一下,这一定会对您有帮助:)

http://technet.microsoft.com/en-us/library/ms151198.aspx http://technet.microsoft.com/en-us/library/ms151198.aspx

generate the scripts: right click dev db tasks- generate scripts next (if welcome screen appears) ensure correct db is selected and click the scheckbox next to "script all objects int he selected database" change any options as necessary (ie, set the script data option to true) click next click next click finish click close copy and paste generated scripts on target server (you may have to delete and recreate the db on the target server) 生成脚本:右键单击dev db task-下一步生成脚本(如果出现欢迎屏幕),确保选择了正确的db,然后单击“将所有对象集成到所选数据库中的脚本”旁边的scheckbox,根据需要更改任何选项(即,设置脚本数据选项为true),单击下一步,单击下一步,单击完成,单击关闭,关闭复制并粘贴在目标服务器上生成的脚本(您可能必须在目标服务器上删除并重新创建数据库)

Another option is to purchase Redgate's (or any similer tools) SQL Compare and SQL Data compare. 另一种选择是购买Redgate(或任何类似工具)的SQL Compare和SQL Data compare。 it'll tell you what's different and allow you to generate the scripts to only update what has changed. 它会告诉您有什么不同,并允许您生成脚本以仅更新已更改的内容。

There are a number of options. 有很多选择。

  1. Detach the db on dev machine, copy the db files to prod and then attach db. 在开发机器上分离数据库,将数据库文件复制到prod,然后附加数据库。
  2. Make a full backup of dev db and restore the backup on prod. 对dev db进行完整备份,然后在prod上还原备份。
  3. Use the Copy Database wizard in Microsoft SQL Server Management Studio. 使用Microsoft SQL Server Management Studio中的“复制数据库”向导。

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

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