在 SQL Server Express 中复制数据库?
我想复制我拥有的数据库,但将其与测试数据库保存在同一服务器上。然而,我发现的一切都是使用复制数据库向导(我使用的是 MS SQL Server Express)。
说明始终显示:在 SQL Server Management Studio 的对象资源管理器中,展开数据库,右键单击数据库,指向任务,然后单击复制数据库。
我没有复制数据库选项。我以管理员身份运行,所以不知道为什么我缺少它 - 这是我必须单独安装的东西吗?我无法执行分离/附加,因为它正在复制到同一服务器。我尝试分离、复制 MDF/LDF、重命名、附加,但正如你可以想象的那样,这搞砸了:)我不太擅长用 SQL 来以编程方式完成这一切。有我可以使用的工具吗?
I would like to make a copy of a database I have but keep it on the same server as a test database. However, everything I have found is to use the copy database wizard (I am using MS SQL Server Express).
The instructions always say: In SQL Server Management Studio, in Object Explorer, expand Databases, right-click a database, point to Tasks, and then click Copy Database.
I don't have the Copy Database option. I am running as an admin, so no clue why it is missing for me - is it something I have to install separately? I can't do the Detach/Attach since it is copying to the same server. I tried detaching, copying the MDF/LDF, renaming, attaching but as you can imagine that messed a ton up :) I am not great with SQL to do it all programatically. Is there a tool out there I could use?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(13)
在 SSMS 2008 中,您可以执行以下操作:
创建要复制的数据库的备份
在 SSMS 中,右键单击“数据库”并选择“还原数据库'
从“还原源”部分的“来自数据库”下拉列表中选择要复制的数据库
在“目标”的“目标数据库”字段中输入新数据库的名称“用于还原”部分 - 这不能是现有数据库的名称。
单击“确定”
您就完成了! :)
In SSMS 2008 you can do this:
Create a backup of the database you want to copy
In SSMS, right-click 'Databases' and select 'Restore Database'
Select the database you wish to copy from the 'From database' drop-down list in the 'Source for restore' section
Enter the name of the new database in the 'To database' field in the 'Destination for Restore' section - this cannot be the name of an existing database.
Click OK
You're done! :)
在 SQL Server Express 2012 中,您可以执行以下步骤:
这将使用正确的表设置(例如“默认值”和“自动增加”等)“克隆”数据库。
In SQL Server Express 2012 you can do following steps:
this will "clone" the Database with the correct table settings such as the "default value" and "auto increase" etc.
SQL Express数据库有一个导出按钮,我只是将数据库导出到同一服务器上的新数据库,它正在复制数据库。只需右键单击数据库名称即可。
SQL Express database has an export button, I just exported the database to a new database on the same server, it is copying the database. Just right-click on the database name.
执行以下步骤在 SQL Express 中创建数据库副本
我能够使用此方法复制我的 SQL Express 系统上的数据库
Take these steps to make a copy of the database in SQL Express
I was able to copy a database on my SQL Express system with this method
我在使用 SQL Express 2012 创建数据库副本时遇到问题。
我已经通过备份和恢复的方法解决了。
进行备份后我使用:恢复 - >文件和文件组
下一步是为新数据库编写新名称并设置源:
指向源文件
最后,覆盖现有数据库必须选择替换
并为扩展名为 mdf 和 ldf 的新文件设置与现有文件不同的名称,其中: Restore as
此方法对我有用
I had a problem creating a copy of my database as well using SQL Express 2012.
I have solved it by the backup and restore method.
After making the backup I used: restore -> files and file groups
Next step was to write a new name for the new database and set the source:
Pointing the source file
and finally, a overwrite the existing database with replace must be selected
and set names for new files with extension mdf and ldf that are different from the existing where is: Restore as
This method worked for me
请注意,如果您使用的是 SQL Server Express 2012,请转到“文件”选项,并确保目标文件(还原为列)与原始文件 *.mdf 和 *.log 不同
(我尝试放置图像,但需要 10 声望 :p)
Just be aware if you are using SQL Server Express 2012 of going to the option Files and make sure that the destination files (Restore As column) are different from the original files *.mdf and *.log
( I tried to put an image but need 10 reputation :p)
解决方案肯定是创建备份并还原它,但请确保还原的副本指向不同的 .mdf 和 .ldf 文件。
以下是如何使用 SSMS 2014 和 SQL Server 12 安装进行检查:假设您正在本地磁盘上创建和恢复备份。
The solution is definitely to create a backup and restore it, but ensure that you're restored copy is pointing to different .mdf and .ldf files.
Here's how to check that using SSMS 2014 and a SQL Server 12 installation: assuming you're creating and restoring backups on your local disk.
我不相信管理器的 Express 版本会有复制数据库功能。您是否考虑过通过备份和恢复方法进行复制?
http://msdn.microsoft.com/en-us/library/ms190436.aspx
I do not believe the Express version of the manager will have the copy database feature. Have you considered copying via the backup and restore method?
http://msdn.microsoft.com/en-us/library/ms190436.aspx
我发现问题了!单击数据库,还原,然后执行以下操作:
选择恢复位置并写入目标数据库名称后,转到文件[图片上的注释1]并将最右侧的列文件名更改为与原始[图片上的注释2]不同的名称 然后就可以了:)
I found the problem! Click on Databases, restore, then do the following:
After choosing from where to restore, and writing destination db name, go to files [annotation 1 on picture] and change the very right column files names to different than original [annotation 2 on picture] then it works :)
我认为您可以尝试将数据导入到新数据库。
I think you could try import data to a new database.
我只是想到了一个非常漂亮的方法来解决这个问题:)所以我想我应该发布我的想法。请注意,这是“未经测试的”,但我认为它会起作用。
生产服务器,但不一定是)
机器,然后您可以在您的开发机器上进行“恢复”,
然后在您的开发中执行“复制数据库”
机器(创建数据库的新副本)
希望这可以帮助一些人:)
干杯,
杰夫
I just thought of a really nifty way to get around this :) So I thought I should post my idea. Note that this is 'untested' but I think it will work.
production server, but it doesn't have to be)
machine, you can then do a "Restore" onto your development machine,
then do a "Copy Database" afterwards also on your development
machine (to create a new copy of the DB)
Hope this helps out a few people :)
Cheers,
Jeff
至于您的问题的第一部分(为什么您在数据库的任务下看不到此复制数据库向导选项),答案确实是您正在运行 SQL Server Express 。 SQL Server Express 不支持此复制数据库功能所依赖的 SQL Server 代理功能,因此未显示复制数据库功能(但许多在线资源未能进行该观察)。
幸运的是,大多数其他人都解决了您问题的第二部分(否则如何完成任务),并且几乎所有人都指出使用现有的备份和恢复选项(Express 中确实存在)或导出/导入(也存在于 Express 中,我可以确认)。
As for the first part of your question (why do you not see this Copy Database Wizard option under Tasks for your dbs), the answer is indeed in the fact that you are running SQL Server Express. SQL Server Express doesn't support the SQL Server Agent feature, which this Copy DB feature relies upon, so the Copy DB feature is not shown (but many online resources fail to make that observation).
Fortunately, most everyone else has addressed the second part of your question (how to achieve the task otherwise), and nearly all point out using the existing backup and restore options (which DO exist in Express), or the export/import (which also exists in Express, I can confirm).
尝试备份数据库,然后将其恢复到全新的数据库中。
Try making a backup of your database, and restoring it into a brand new database.