Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to improve the efficiency of SQLServer Delete data

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Scene:

Delete a large table of 300 million.

It is realized through the intermediate table.

First write the data that needs to be archived into the history table Cou_History..Cou_History.

Write the field conditions that need to delete the table to the intermediate table.

Select SysNo into COU_temp01

FROM COU

WHERE EXISTS (SELECT 1 FROM Cou_History..Cou_History a WHERE a.SysNo=COU.SysNo)

Then use the intermediate table as the intermediate condition to delete the relevant data of the main table. Then delete the intermediate table field data that has been deleted in the main table.

The following SQL loop is executed until all have been deleted.

DELETE TOP (1000)

From COU

Where SysNo in

(select top 1000 * from COU_temp01)

Delete top (1000) from COU_temp01

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report