在 SQL Server Express 中复制数据库?

发布于 2024-10-04 18:22:53 字数 334 浏览 5 评论 0原文

我想复制我拥有的数据库,但将其与测试数据库保存在同一服务器上。然而,我发现的一切都是使用复制数据库向导(我使用的是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(13

猫卆 2024-10-11 18:22:53

在 SSMS 2008 中,您可以执行以下操作:

  1. 创建要复制的数据库的备份

  2. 在 SSMS 中,右键单击“数据库”并选择“还原数据库'

  3. 从“还原源”部分的“来自数据库”下拉列表中选择要复制的数据库

  4. 在“目标”的“目标数据库”字段中输入新数据库的名称“用于还原”部分 - 这不能是现有数据库的名称。

  5. 单击“确定”

您就完成了! :)

In SSMS 2008 you can do this:

  1. Create a backup of the database you want to copy

  2. In SSMS, right-click 'Databases' and select 'Restore Database'

  3. Select the database you wish to copy from the 'From database' drop-down list in the 'Source for restore' section

  4. 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.

  5. Click OK

You're done! :)

不可一世的女人 2024-10-11 18:22:53

在 SQL Server Express 2012 中,您可以执行以下步骤:

  1. 创建要复制的数据库的备份
  2. 右键单击​​“数据库”并选择“还原文件和文件组”
  3. 在“到数据库”字段中输入新数据库的名称。
  4. 选择“从设备”,然后选择您在第一步中备份的文件,
  5. 单击“确定”,

这将使用正确的表设置(例如“默认值”和“自动增加”等)“克隆”数据库。

In SQL Server Express 2012 you can do following steps:

  1. Create a backup of the database you want to copy
  2. right-click "Databases" and select "Restore Files and Filegroups"
  3. Enter the name of the new database in the "To database" field.
  4. Select "From device" and then select the file that you backuped in the first step
  5. click "OK"

this will "clone" the Database with the correct table settings such as the "default value" and "auto increase" etc.

难得心□动 2024-10-11 18:22:53

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.

神也荒唐 2024-10-11 18:22:53

执行以下步骤在 SQL Express 中创建数据库副本

  1. 停止 SQL
  2. 将数据库的 mdf、ldf 和任何其他文件复制到新位置(确保获取日志文件)
  3. 更改每个复制文件的名称
  4. 启动 SQL
  5. 正确-单击 SSMQ 中的数据库并选择附加
  6. 确保更改“附加为”列中的名称
  7. 将“数据库详细信息”下部窗格中的文件位置更新为复制文件(尤其是日志文件)的位置

我能够使用此方法复制我的 SQL Express 系统上的数据库

alt text

Take these steps to make a copy of the database in SQL Express

  1. Stop SQL
  2. Copy the mdf, ldf and any other file for the db to a NEW location (make sure you get the log file)
  3. Change the name of each copied file
  4. Start SQL
  5. Right-click Database in SSMQ and select attach
  6. Make sure you change the name in the column "Attach As"
  7. Update the file location in the lower pane of "Database Details" to the location of your copied files (especially that log file)

I was able to copy a database on my SQL Express system with this method

alt text

木落 2024-10-11 18:22:53

我在使用 SQL Express 2012 创建数据库副本时遇到问题。
我已经通过备份和恢复的方法解决了。
进行备份后我使用:恢复 - >文件和文件组
选择恢复选项

下一步是为新数据库编写新名称并设置源:

设置源并命名新数据库

指向源文件

选择备份文件

最后,覆盖现有数据库必须选择替换
并为扩展名为 mdf 和 ldf 的新文件设置与现有文件不同的名称,其中: Restore as

为 mdf 和 ldf 文件设置新名称

此方法对我有用

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
choosing restore option

Next step was to write a new name for the new database and set the source:

set source and named new database

Pointing the source file

choosing backup 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

set new names for mdf and ldf files

This method worked for me

深海夜未眠 2024-10-11 18:22:53

请注意,如果您使用的是 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)

白芷 2024-10-11 18:22:53

解决方案肯定是创建备份并还原它,但请确保还原的副本指向不同的 .mdf 和 .ldf 文件。

以下是如何使用 SSMS 2014 和 SQL Server 12 安装进行检查:假设您正在本地磁盘上创建和恢复备份。

  • 创建现有数据库的备份
    • 右键单击数据库,然后选择“任务”下的“备份...”。
    • (如果您将该位置保留为默认位置,则恢复时无需在下一步中寻找备份。)
  • 将备份恢复到新数据库:
    • 右键点击数据库,选择“恢复数据库”
    • 选择“设备”
    • 点击省略号按钮(“...”)打开“选择备份设备”对话框。
    • 选择“文件”作为备份媒体类型,然后点击“添加”按钮
    • 选择您刚刚制作的备份,点击“确定”(两次)
    • 现在,返回“恢复数据库”对话框,为目标数据库输入新名称
    • 点击“选择页面”下的“文件”,并确保“还原为”指向尚不存在的 .mdf 和 .ldf 文件名
    • 点击“确定”!

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.

  • Create a backup of your existing database
    • Right click the database, and choose "back up..." under "tasks."
    • (If you leave the location as the default, you don't have to hunt for the back up in the next step when you restore.)
  • Restore your backup to a NEW database:
    • Right click on databases, choose "restore database"
    • Select "device"
    • Click the ellipsis button ("...") to open the "Selct Backup devices" dialog.
    • Choose "File" as the backup media type and click the "add" button
    • Select the backup you just made, click ok (twice)
    • Now, back in the "restore database" dialog, type a new name for your destination database
    • Click "files" under "select a page" and make sure that "restore as" is pointing to .mdf and .ldf file names that do not already exist
    • Click ok!
够钟 2024-10-11 18:22:53

我不相信管理器的 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

左耳近心 2024-10-11 18:22:53

我发现问题了!单击数据库,还原,然后执行以下操作:
选择恢复位置并写入目标数据库名称后,转到文件[图片上的注释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 :)

> SEE THE PICTURE HERE <

泪意 2024-10-11 18:22:53

我认为您可以尝试将数据导入到新数据库。

  1. 在本地sql服务器中创建一个空数据库
  2. 右键单击新数据库->任务->导入数据
  3. 在 SQL Server 导入和导出向导中,选择产品环境的服务器名称作为数据源。并选择您的新数据库作为目标数据。

I think you could try import data to a new database.

  1. Create an empty database in your local sql server
  2. Right click on the new database -> tasks -> import data
  3. In the SQL Server Import and Export Wizard, select product env's servername as data source. And select your new database as the destination data.
人间☆小暴躁 2024-10-11 18:22:53

我只是想到了一个非常漂亮的方法来解决这个问题:)所以我想我应该发布我的想法。请注意,这是“未经测试的”,但我认为它会起作用。

  1. 做一个“备份...”数据库(理论上这是在你的
    生产服务器,但不一定是)
  2. 将备份文件(从您的产品服务器)复制到您的开发计算机上
  3. 假设您在开发中使用 SSMS Developer Edition
    机器,然后您可以在您的开发机器上进行“恢复”,
    然后在您的开发中执行“复制数据库”
    机器(创建数据库的新副本)
  4. 现在在刚刚创建的新数据库上执行“备份...”,将备份文件复制到(到生产服务器)并在 sql server express 上执行“恢复”服务器:)

希望这可以帮助一些人:)

干杯,

杰夫

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.

  1. Do a "Back Up..." database (theoretically this is on your
    production server, but it doesn't have to be)
  2. Copy the backup file (from your prod server) onto your development machine
  3. Assuming you're using SSMS Developer Edition on your development
    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)
  4. Now do a "Back Up..." on the new DB you just created, copy the backup file (to your production server) and do a "Restore" on the sql server express server :)

Hope this helps out a few people :)

Cheers,

Jeff

半岛未凉 2024-10-11 18:22:53

至于您的问题的第一部分(为什么您在数据库的任务下看不到此复制数据库向导选项),答案确实是您正在运行 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).

残龙傲雪 2024-10-11 18:22:53

尝试备份数据库,然后将其恢复到全新的数据库中。

  • 创建新数据库。
  • 对原始文件进行完整备份。
  • 右键单击您的新数据库,然后单击“恢复”。
  • 导航到您的 .BAK,并确保 .mdf 和 .ldf 与新的匹配。

Try making a backup of your database, and restoring it into a brand new database.

  • Create new DB.
  • Make a full backup of your original.
  • Right click on your new DB, hit restore.
  • Navigate to your .BAK, and ensure the .mdf and .ldf match the new.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文