久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何逐塊更新巨大的記錄

how to update the huge records chunk by chunk(如何逐塊更新巨大的記錄)
本文介紹了如何逐塊更新巨大的記錄的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我有大約 500 000 的數(shù)據(jù).我需要將 First name 和 Second name 的數(shù)據(jù)更新為大寫

I have data around 500 000. I need to update the data of First name and Second name to capital letters

我的樣本數(shù)據(jù):

declare @T table(Firstname varchar(max),Secondname varchar(max))
insert into @T values ('ch bhaskar rao ','sridhar kolla ')
insert into @T values ('hemanth kumar','varun chenna-reddy')
insert into @T values ('mohan vara prasad','raju t d p durga raju')
insert into @T values ('police mutual','police mutual')

我的腳本:

;WITH CTE AS (
    select (
        select upper(T.N.value('.', 'char(1)')),
            lower(stuff(T.N.value('.', 'varchar(max)'), 1, 1, ''))+(CASE WHEN RIGHT(T.N.value('.', 'varchar(max)'), 1)='-' THEN '' ELSE ' ' END)
        from X.Secondname.nodes('/N') as T(N)
        for xml path(''), type
    ).value('.', 'varchar(max)') As Secondname
    from 
    (
        select 
         cast('<N>'+replace(replace(replace(Secondname, ' ', '</N><N>'),' ', '</N><N>'),'-','-</N><N>')  +'</N>' as xml) as Secondname
        from @T
    ) as X 
)
UPDATE T 
SET
    Secondname = C.Secondname
FROM 
    CTE C 
    INNER JOIN @T T 
        ON   T.Secondname = C.Secondname

Select Secondname from @T 

當(dāng)數(shù)據(jù)大約為 10 000 條記錄時(shí)它工作正常,但是當(dāng)我嘗試更新大約 500 萬(wàn)條記錄時(shí)系統(tǒng)掛斷了.如何像 10000 和 10000 那樣逐塊更新,以免系統(tǒng)負(fù)擔(dān)?

It is working fine when data is around 10 000 records but system getting hanged up when I'm trying to update huge records around 5 millions. How to update chunk by chunk like 10000 and again 10000, so that system will not burdened?

推薦答案

您可以像下面提到的那樣分塊更新表格:

You can update the table in chunks like mentioned below:

declare @i int = 2
declare @j int = 1

    while @j > 0 
        begin 
            begin transaction
            update top (@i) a
            set a.firstname = upper(a.firstname),
                a.secondname = upper(a.secondname)
            from aa as a
            where a.firstname collate latin1_general_cs_as <> upper(a.firstname)
            set @j = @@rowcount
            commit transaction

        end

您可以根據(jù)需要更改上述代碼.如果這有幫助,請(qǐng)告訴我.

you can change the above code as per your needs. Let me know if this helps.

這篇關(guān)于如何逐塊更新巨大的記錄的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Modify Existing decimal places info(修改現(xiàn)有小數(shù)位信息)
The correlation name #39;CONVERT#39; is specified multiple times(多次指定相關(guān)名稱“CONVERT)
T-SQL left join not returning null columns(T-SQL 左連接不返回空列)
remove duplicates from comma or pipeline operator string(從逗號(hào)或管道運(yùn)算符字符串中刪除重復(fù)項(xiàng))
Change an iterative query to a relational set-based query(將迭代查詢更改為基于關(guān)系集的查詢)
concatenate a zero onto sql server select value shows 4 digits still and not 5(將零連接到 sql server 選擇值仍然顯示 4 位而不是 5)
主站蜘蛛池模板: 日本三级电影在线免费观看 | 欧美日韩中文字幕在线 | 欧美影院 | 日韩一区二区三区视频 | 91精品久久久 | 国产精品一区二区久久 | 欧美综合在线视频 | 欧美综合久久 | 国产精品久久久久久久久久久久久久 | 国产精品成人久久久久 | 久久久这里都是精品 | 成人午夜 | 在线视频一区二区 | 成人精品国产一区二区4080 | 在线欧美亚洲 | 欧美一级淫片免费视频黄 | av大全在线 | www.v888av.com| 日韩在线免费 | 8x国产精品视频一区二区 | 亚洲视频欧美视频 | 国产91丝袜在线18 | 黑人粗黑大躁护士 | 欧美一级大黄 | 四虎影院免费在线 | 日韩精品一区二区在线观看 | 欧美一级在线视频 | 亚洲国产欧美国产综合一区 | 中文字幕精品一区二区三区精品 | 日韩一区不卡 | 日本不卡一区二区三区 | 国产一区二区三区免费 | 久久人人爽人人爽人人片av免费 | 成人免费精品视频 | 日韩毛片网 | 男女视频在线免费观看 | 中文字幕高清 | 成年人在线视频 | 国产xxxx搡xxxxx搡麻豆 | 黄色网址在线免费播放 | 男女网站免费 |