How to prevent SSIS from importing data from a file that already exist in database?

我与影子孤独终老i 提交于 2020-01-15 03:08:47

问题


Everyday i load some csv data into my table. And my table has date column, now i need to use rollback function, such that, if the data already exists in my table it has to rollback, else it has to inserts based on my Asofdate parameter.

I know it is little confusing, let me be more clear.

my table has eid, ename, asofdate columns , now when i insert new file every day, it has to see whether that file is already existed in that table based on asofdate, if data exists, it should rollback the data.


回答1:


As @Diego had mentioned, you would use a Lookup transformation within the Data Flow task to achieve the functionality.

Your data flow task would look something like this. Here, the Flat file source reads the CSV file and then passes the data to Lookup transformation. This transformation will check for existing data in the destination table (say the table name is dbo.Destination). The configuration for Lookup transformation is shown in the next screenshots. If there are no matching records, then the data from CSV file will be sent to the OLE DB Destination otherwise, the data will be discarded.

In the Lookup transformation, you will choose the destination database table on the Connection tab. On the Columns section, you will verify all the columns that you would like to check for existing data. Here in this case, the columns eid, name and asofdate coming from CSV file are validated against columns of same names in the database table dbo.Destination. If the incoming values for these three columns match with any rows in the table, the data will not be sent further down the stream.

Hope that gives you an idea.




回答2:


the correct term is not rollback. Rollback is when you insert something and undo your transaction. you should not insert the data if it already exists.

What you need is a lookup transformation between your DBSource and your DBDestination. This lookup should check if data exists on the destination table and, if not, insert it




回答3:


For this kind of requirement you can make use of Insert TRIGGER on table and when inserting data you can check the data exists in table or not , if you want to check for each and every record

or

Before inserting file in the table you can make use of if exists statment, if you just want to check for the records existsor not like this SQL: If Exists Update Else Insert



来源:https://stackoverflow.com/questions/10313612/how-to-prevent-ssis-from-importing-data-from-a-file-that-already-exist-in-databa

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!