SQL Server: how can I truncate and copy in C #?

I am starting a new project. The challenge is basically to move data from a file to a database. Let's say there is one data file per hour, and the file line is converted to one database line.

Technical information:

  • File lines (entries in the database): 10k - 100k
  • Record: 10 x char [100]

My problem is the update process.

I would like:

Solution 1:

  • Leave the actual datatable value in tact (original_table)
  • Move data from file to shadow table (copy_table)
  • When the process is completed:
  • Truncate original_table
  • Bulk copy data from copy_tabletooriginal_table

Solution 2:

  • Add new entries to original_table
  • Delete all entries with the old timestamp
  • Reorganization original_table(reduction, reset index)

Questions:

  • Which solution is more efficient?
  • - ?
  • 4/5 1 3- 2 # ( , Entity Framework)?
+4
3

2 . 1 .

4 5 1 3 2, EntityCommand.ExecuteNonQuery T-SQL - TRUNCATE TABLE original_table.

+2

  • _
  • original_table

? , , , . .

+1

Solution 1: BAD. It has synchronization issues in which a table is not available, which means other programs must handle this.

Solution 2: The same.

What about:

3: Load the new data into the temporary table, then merge them into the original table.

0
source

Source: https://habr.com/ru/post/1536472/


All Articles