Sql: DELETE + INSERT and UPDATE + INSERT

A similar question is asked, but since it always depends on me, I ask for a specific situation separately.

I have a website page that shows some data coming from a database, and to generate data from this database, I need to perform some rather complex queries with multiple connections.

Data is updated once a day (at night).

I would like to pre-generate data for the specified view in order to speed up access to the page.

To do this, I create a table that contains the exact data that I need.

Question: for my situation, is it wise to do a full table cleanup and then insert? or do I need to update, paste?

SQL wise it seems that DELETE + INSERT will be easier (the INSERT part is a single SQL statement).

EDIT: DBMS: MS SQL Server 2008 Ent

+5
source share
7 answers

TRUNCATE will be faster than delete, so if you need to clear the table, do it instead

You did not specify your RDBMS provider, but some of them also have MERGE / UPSERT commands . This allows you to update the table if data exists and is inserted if it does not

+13
source

. , ( ) , , ( DELETE INSERT) .

+1

(MSSQL ) , ? , , , () .

+1

. , , . TRUNCATE, , .

MERGE/UPSERT? MS-SQL, CROSS APPLY, - , .

0

, . , .

0

, , , ? , .

, , . @kevinw

0

SQLMenace , MERGE ! , - , MERGE , , TRUNCATE + INSERT... ( , , , / . INSERT , - , () ). (**)

(**: , , , - , , )

0
source

All Articles