开发者

SQL Server 2008 - To Insert/Update in Main table from Staging table

Once the开发者_高级运维 data is imported in a Staging table through Bulk Insert, then I need to do two steps:

  1. Transformations
  2. Insert/Update in Main table

Is the JOINS are the best tool OR there is something quicker/more efficient to perform these tasks?


I would probably do something like this:

  • make your transformations on that staging table (add additional columns as needed etc.)
  • do the INSERT/UPDATE into the actual data table using the SQL Server 2008 MERGE command which is ideally suited for just this - update some existing rows, insert some new rows (and possibly delete some old "orphaned" rows). It's a single command which can handle just about all insert, update, delete scenario in a single call

See some great articles on how to use the MERGE command:

  • Using SQL Server 2008's MERGE statement
  • SQL Server – 2008 – Introduction to Merge Statement – One Statement for INSERT, UPDATE, DELETE
  • Merge Statement in SQL Server 2008
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜