您好,登錄后才能下訂單哦!
這篇文章主要為大家展示了“數(shù)據(jù)庫中如何修改分區(qū)表的數(shù)據(jù)”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“數(shù)據(jù)庫中如何修改分區(qū)表的數(shù)據(jù)”這篇文章吧。
需求案例:student表中儲存學(xué)生的信息,按照班級進(jìn)行了分區(qū),一個學(xué)生轉(zhuǎn)了班級,他的信息需要在student表中修改。
student表結(jié)構(gòu)語句
create table student(id number(5),name varchar2(10),class_id number(2)) partition by list(class_id)(partition P_01 values (1),partition P_02 values (2));
測試數(shù)據(jù)
insert into student values(1,'xiaoming',1);
insert into student values(2,'xiaohong',1);
insert into student values(2,'xiaohua',2);
insert into student values(2,'xiaoyue',2);
commit;
修改xiaoming的id=3,修改后,數(shù)據(jù)所在的分區(qū)沒有改變。
update student n set n.id=3 where n.name ='xiaoming';
commit;
修改xiaoming到班級2
update student n set n.class_id=2 where n.name ='xiaoming';
執(zhí)行會報錯
原因分析:因為分區(qū)表的數(shù)據(jù)是按分區(qū)規(guī)則存入不同的分區(qū),如果數(shù)據(jù)修改后,不在一個分區(qū)了,數(shù)據(jù)需要先刪除,再插入新的分區(qū),而數(shù)據(jù)庫中對應(yīng)的參數(shù)未設(shè)置,就導(dǎo)致了報錯
解決辦法:
1.導(dǎo)出需要修改的數(shù)據(jù)到臨時表,再臨時表中修改數(shù)據(jù),刪除原表需要修改的數(shù)據(jù),把臨時表的數(shù)據(jù)插入分區(qū)表中
優(yōu)勢:對數(shù)據(jù)庫不用修改參數(shù),可以保證對系統(tǒng)的性能影響小
劣勢:數(shù)據(jù)量大的情況,高水位問題會較明顯
create table student_tmp as select * from student n where n.name ='xiaoming';
update student_tmp n set n.class_id=2 where n.name ='xiaoming';
commit;
delete from student n where n.name ='xiaoming';
commit;
insert into student select * from student_tmp;
commit;
2.開啟數(shù)據(jù)庫 row movement
優(yōu)勢:數(shù)據(jù)庫可以對分區(qū)表進(jìn)行跨分區(qū)修改
劣勢:由于是對數(shù)據(jù)庫的參數(shù)進(jìn)行修改,產(chǎn)生的影響較大,需要進(jìn)行各方面的測試,已考慮對系統(tǒng)的影響降到最低
alter table student enable row movement;
執(zhí)行了這條語句后,再對分區(qū)表進(jìn)行跨分區(qū)修改數(shù)據(jù)就沒有問題了
update student n set n.class_id=2 where n.name ='xiaoming';
commit;
以上是“數(shù)據(jù)庫中如何修改分區(qū)表的數(shù)據(jù)”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。