Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3940324
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:24:18+00:00 2026-05-20T00:24:18+00:00

I have a table with 50+ columns and I need to swap the order

  • 0

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 ORDERDETAILS and as it is, the first two columns are ITEM_ID and ORDER_ID. Once the rename is complete, the table name should still be ORDERDETAILS but the first two columns will be ORDER_ID and ITEM_ID. FWIW, column types and the rest of the columns and their order is irelevent.

Correct me if I’m wrong, but I think the general steps are:

  1. Rename the existing table.
  2. Drop the primary key constraint.
  3. Re-create the table with the correct column order.
  4. List item
  5. Run INSERT INTO .. SELECT to move the data from temp to the table in step #3.
  6. Drop the temp table.

I have little experience with Oracle so perhaps I’m missing a step or two.

Does a primary key imply an index in Oracle? Does dropping the primary key also drop the index?

SQL examples are much appreciated.

EDIT: Un-sincere thanks to those who question why it needs done instead of providing help. To answer your question as to why it needs done: I’m following orders from someone else who says I need to do it this way and the order of the columns DOES matter. My thoughts/opinions on this are irrelevent.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T00:24:18+00:00Added an answer on May 20, 2026 at 12:24 am

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with two columns where I need one ( columnB )
I have this table where columns correspond to names: i.e. 11 = first, 12
First the example: http://jsfiddle.net/5S3mk/3/ I have a table whose columns need to be sortable
I have table that has two columns and I need to concatenate these two
I have a table whose columns are varchar(50) and a float . I need
I have a table with 11 columns, but I need to get only 2
I have a table that I need to update where all columns are optionally
I have a N to N table with columns: Id (primary key) (I need
I have a table with more than 100 columns. I need to join it
I have three columns in mysql table: tax_id, company_name, store_name. I need that tax_id

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.