How to automatically truncate string when do bulk insert?

后端 未结 3 1418
故里飘歌
故里飘歌 2021-02-13 21:13

I want to insert many rows (constructed from Entity Framework objects) to SQL Server. The problem is, some of string properties have length exceeded length of column in database

3条回答
  •  粉色の甜心
    2021-02-13 21:44

    Always use a staging/load table for bulk actions.

    Then you can process, clean, scrub etc the data before flushing to the real table. This includes, LEFTs, lookups, de-duplications etc

    So:

    1. Load a staging table with wide columns
    2. Flush from staging to "real" table using INSERT realtable (..) SELECT LEFT(..), .. FROM Staging

提交回复
热议问题