如何使用SSIS复制和覆盖SQL Server 2005中的数据库?

时间:2022-10-28 23:55:07

I HAVE to be missing something really simple here!

我必须在这里找到一些非常简单的东西!

I have a database in my development environment called Project. I have a database in my test environment called Project_UAT.

我的开发环境中有一个名为Project的数据库。我的测试环境中有一个名为Project_UAT的数据库。

I've created an SSIS package that successfully copied my database from Project to Project_UAT. I'm pretty sure this eliminates most permission and configuration issues.

我已经创建了一个SSIS包,成功地将我的数据库从Project复制到了Project_UAT。我很确定这会消除大多数权限和配置问题。

Now, I want to re-create the package and this time allow it to overwrite the destination, which is Project_UAT. This is simply because from time to time I want to click a button in the Microsoft SQL Management Studio that pushes the new database schema, data, users, and everything, out to my testing environment. I WANT to overwrite the data.

现在,我想重新创建包,这次允许它覆盖目标,即Project_UAT。这只是因为我不时想单击Microsoft SQL Management Studio中的一个按钮,该按钮将新的数据库模式,数据,用户和所有内容推送到我的测试环境。我想覆盖数据。

So I create the package just like I did before, but this time I specify the already-existing database name as the "Destination database" and I select the radio button called "Drop any database on the destination server with the same name, then continue with the database transfer, overwriting existing database files."

所以我像以前一样创建包,但是这次我将已存在的数据库名称指定为“目标数据库”,然后选择名为“使用相同名称删除目标服务器上的任何数据库”的单选按钮,然后继续用数据库传输,覆盖现有的数据库文件。“

I click Next, and what does it tell me?

我点击下一步,它告诉我什么?

"Database name already exists at destination"

“数据库名称已存在于目的地”

Well, I KNOW! I just told you I want to overwrite it!

好吧,我知道!我刚刚告诉你我要覆盖它!

How do I make this work?

我该如何工作?

4 个解决方案

#1


2  

Not sure if I am missing the point but why do you not use a task to drop/delete the existing database prior to your deployment step?

不确定我是否忽略了这一点,但为什么在部署步骤之前不使用任务删除/删除现有数据库?

Perhaps you could qualify the SSIS Component Tasks you are using within your SSIS package.

也许您可以在SSIS包中使用您正在使用的SSIS组件任务。

Cheers, John

#2


2  

You can add an Execute SQL Task into the Control Flow to drop the database. Just set the SQLStatement property to

您可以将“执行SQL任务”添加到“控制流”中以删除数据库。只需将SQLStatement属性设置为

DROP DATABASE Project_UAT

After this step is executed the new copy of the Project_UAT database won't have to overwrite the old one.

执行此步骤后,Project_UAT数据库的新副本将不必覆盖旧的副本。

#3


1  

I had this problem because I deleted the database before hand. The database is not in the destination folder, but SQL Server 2008 still thinks it is there. Refresh didn't work. And SQL Server wouldn't honor the selection of "Drop any database on the destination server..." It just complained that the database already existed.

我有这个问题,因为我手头删除了数据库。数据库不在目标文件夹中,但SQL Server 2008仍然认为它在那里。刷新不起作用。并且SQL Server不会选择“删除目标服务器上的任何数据库......”它只是抱怨数据库已经存在。

#4


0  

Guys this is a common sense solution. A lot of complexity for nothing.

伙计这是一个常识解决方案。没什么复杂的。

Backup the destination database you want to copy to and delete the destination database.

备份要复制的目标数据库并删除目标数据库。

Open the copy database wizard and follow the steps.

打开复制数据库向导,然后按照步骤操作。

Use the detach and attach method.

使用分离和附加方法。

When you get to the configure destination database use the option if destination database exists select drop database on destination server with same name.

当您到达配置目标数据库时,如果目标数据库存在,请使用选项选择具有相同名称的目标服务器上的drop database。

Now it will continue to the next screen.

现在它将继续到下一个屏幕。

But this only works if you delete the destination database first before starting the wizard.

但这仅在您启动向导之前首先删除目标数据库时才有效。

I may have missed something but this worked for me.

我可能错过了一些东西,但这对我有用。

#1


2  

Not sure if I am missing the point but why do you not use a task to drop/delete the existing database prior to your deployment step?

不确定我是否忽略了这一点,但为什么在部署步骤之前不使用任务删除/删除现有数据库?

Perhaps you could qualify the SSIS Component Tasks you are using within your SSIS package.

也许您可以在SSIS包中使用您正在使用的SSIS组件任务。

Cheers, John

#2


2  

You can add an Execute SQL Task into the Control Flow to drop the database. Just set the SQLStatement property to

您可以将“执行SQL任务”添加到“控制流”中以删除数据库。只需将SQLStatement属性设置为

DROP DATABASE Project_UAT

After this step is executed the new copy of the Project_UAT database won't have to overwrite the old one.

执行此步骤后,Project_UAT数据库的新副本将不必覆盖旧的副本。

#3


1  

I had this problem because I deleted the database before hand. The database is not in the destination folder, but SQL Server 2008 still thinks it is there. Refresh didn't work. And SQL Server wouldn't honor the selection of "Drop any database on the destination server..." It just complained that the database already existed.

我有这个问题,因为我手头删除了数据库。数据库不在目标文件夹中,但SQL Server 2008仍然认为它在那里。刷新不起作用。并且SQL Server不会选择“删除目标服务器上的任何数据库......”它只是抱怨数据库已经存在。

#4


0  

Guys this is a common sense solution. A lot of complexity for nothing.

伙计这是一个常识解决方案。没什么复杂的。

Backup the destination database you want to copy to and delete the destination database.

备份要复制的目标数据库并删除目标数据库。

Open the copy database wizard and follow the steps.

打开复制数据库向导,然后按照步骤操作。

Use the detach and attach method.

使用分离和附加方法。

When you get to the configure destination database use the option if destination database exists select drop database on destination server with same name.

当您到达配置目标数据库时,如果目标数据库存在,请使用选项选择具有相同名称的目标服务器上的drop database。

Now it will continue to the next screen.

现在它将继续到下一个屏幕。

But this only works if you delete the destination database first before starting the wizard.

但这仅在您启动向导之前首先删除目标数据库时才有效。

I may have missed something but this worked for me.

我可能错过了一些东西,但这对我有用。