Re-order columns of table in Oracle

前端 未结 5 783
粉色の甜心
粉色の甜心 2020-12-07 20:18

I have a table with 50+ columns and I need to swap the order of the first two columns. What is the best way to accomplish this using Oracle? Assume the table name is ORDERDE

5条回答
  •  失恋的感觉
    2020-12-07 21:05

    Look at the package DBMS_Redefinition. It will rebuild the table with the new ordering. It can be done with the table online.

    As Phil Brown noted, think carefully before doing this. However there is overhead in scanning the row for columns and moving data on update. Column ordering rules I use (in no particular order):

    • Group related columns together.
    • Not NULL columns before null-able columns.
    • Frequently searched un-indexed columns first.
    • Rarely filled null-able columns last.
    • Static columns first.
    • Updateable varchar columns later.
    • Indexed columns after other searchable columns.

    These rules conflict and have not all been tested for performance on the latest release. Most have been tested in practice, but I didn't document the results. Placement options target one of three conflicting goals: easy to understand column placement; fast data retrieval; and minimal data movement on updates.

提交回复
热议问题