如何在SSIS中插入新记录之前清空目标表?

时间:2022-10-03 23:50:04

I use SSIS to generate and transform new data for later use in a new system. I have a problem every time I run my SSIS Package, it keeps inserting new records to my destination tables.

我使用SSIS生成和转换新的数据,以便以后在新的系统中使用。我每次运行SSIS包时都会遇到一个问题,它总是向目标表插入新记录。

How can I empty my destination table (/OLE DB Destination) first and then inserting the newly generated records?

如何先清空目标表(/OLE DB destination),然后插入新生成的记录?

Currently the workaround for this problem is performing a delete from DestTable before running my package.

目前,解决这个问题的方法是在运行我的包之前执行从DestTable的删除操作。

4 个解决方案

#1


34  

Put your delete statement in an Execute SQL Task. Then make it the first component of your flow. The component looks something like this:

将delete语句放在执行SQL任务中。然后将它作为流的第一个组件。这个组件看起来是这样的:

如何在SSIS中插入新记录之前清空目标表?

#2


27  

Create an Execute SQL task. Have it run first. For the sqlstatment do.

创建一个执行SQL任务。它第一次运行。sqlstatment做。

Truncate table DestTable

Using truncate table is better then using delete as it ignores all the indexes and just removes everything.

使用truncatetable比使用delete要好,因为它会忽略所有的索引并删除所有的索引。

For a little background info. I will try and explain why you should use truncate table instead of delete table. Delete table is a row based operation this means that each row is deleted. Truncate table is a data page operation the entire data page is delocated. If you have a table with a million rows it will be much faster to truncate the table then it would be to use a delete table statment.

获取一些背景信息。我将尝试解释为什么应该使用truncatetable而不是delete table。删除表是一个基于行的操作,这意味着每一行都被删除。truncatetable是一种数据页操作,对整个数据页进行delocated。如果有一个表有一百万行,那么截断该表的速度会快得多,那么就需要使用delete table语句。

#3


6  

One caveat about using Truncate table, it does run better for the reasons stated. However it also requires additional privileges for your SSIS System account. You should be sure that those are available to you in Production, otherwise you will have to use Delete.

关于使用truncatetable需要注意的一点是,由于所述的原因,它确实运行得更好。但是,它还需要您的SSIS系统帐户附加特权。您应该确保这些内容在生产中是可用的,否则必须使用Delete。

MSDN Reference

MSDN参考

#4


-1  

you need to use this

你需要用这个

truncate table table_name

this empties the table

这倒空表

#1


34  

Put your delete statement in an Execute SQL Task. Then make it the first component of your flow. The component looks something like this:

将delete语句放在执行SQL任务中。然后将它作为流的第一个组件。这个组件看起来是这样的:

如何在SSIS中插入新记录之前清空目标表?

#2


27  

Create an Execute SQL task. Have it run first. For the sqlstatment do.

创建一个执行SQL任务。它第一次运行。sqlstatment做。

Truncate table DestTable

Using truncate table is better then using delete as it ignores all the indexes and just removes everything.

使用truncatetable比使用delete要好,因为它会忽略所有的索引并删除所有的索引。

For a little background info. I will try and explain why you should use truncate table instead of delete table. Delete table is a row based operation this means that each row is deleted. Truncate table is a data page operation the entire data page is delocated. If you have a table with a million rows it will be much faster to truncate the table then it would be to use a delete table statment.

获取一些背景信息。我将尝试解释为什么应该使用truncatetable而不是delete table。删除表是一个基于行的操作,这意味着每一行都被删除。truncatetable是一种数据页操作,对整个数据页进行delocated。如果有一个表有一百万行,那么截断该表的速度会快得多,那么就需要使用delete table语句。

#3


6  

One caveat about using Truncate table, it does run better for the reasons stated. However it also requires additional privileges for your SSIS System account. You should be sure that those are available to you in Production, otherwise you will have to use Delete.

关于使用truncatetable需要注意的一点是,由于所述的原因,它确实运行得更好。但是,它还需要您的SSIS系统帐户附加特权。您应该确保这些内容在生产中是可用的,否则必须使用Delete。

MSDN Reference

MSDN参考

#4


-1  

you need to use this

你需要用这个

truncate table table_name

this empties the table

这倒空表