Oracle 11g rename. Guaranteed to be atomic?

前端 未结 5 1768
伪装坚强ぢ
伪装坚强ぢ 2021-01-13 13:00

I have some (5) rename statements in a plsql script

drop table new;
rename old to new;

\"old\" tables hold very valuable information.

5条回答
  •  别那么骄傲
    2021-01-13 13:48

    If you're worried about the time between the drop and the rename, here is another idea: Use a view that points to the "correct underlying table".

    You'd start with

    CREATE VIEW someName as Select * From OldTable;
    

    Then you can set up your newTable. When you're ready, then just

    CREATE OR REPLACE View someName as Select * From NewTable;
    

    Then you can drop your OldTable. Next time you get some new data, build another NewTable_2 (or reuse OldTable .. then it's probably better to use Table1 and Table2) and redefine the view again.

    The view is as simple as it gets, so it should be updatable without a problem. The only tricky thing is to always build a new table (or toggle between two tables), but this shouldn't be too difficult to set up and probably easier than totally avoiding any problems that might occur with your original suggestion.

提交回复
热议问题