Monday, 15 June 2015

sql - Re-order columns of table in Oracle -



sql - Re-order columns of table in Oracle -

i have table 50+ columns , need swap order of first 2 columns. best way accomplish using oracle? assume table name orderdetails , is, first 2 columns item_id , order_id. 1 time rename complete, table name should still orderdetails first 2 columns order_id , item_id. fwiw, column types , rest of columns , order irelevent.

correct me if i'm wrong, think general steps are:

rename existing table. drop primary key constraint. re-create table right column order. list item run insert .. select move info temp table in step #3. drop temp table.

i have little experience oracle perhaps i'm missing step or two.

does primary key imply index in oracle? dropping primary key drop index?

sql examples much appreciated.

edit: un-sincere question why needs done instead of providing help. reply question why needs done: i'm next orders else says need way , order of columns matter. thoughts/opinions on irrelevent.

look @ bundle dbms_redefinition. rebuild table new ordering. can done table online.

as phil brownish noted, think before doing this. there overhead in scanning row columns , moving info on update. column ordering rules utilize (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 , have not been tested performance on latest release. have been tested in practice, didn't document results. placement options target 1 of 3 conflicting goals: easy understand column placement; fast info retrieval; , minimal info motion on updates.

sql oracle rename

No comments:

Post a Comment