Unix Technical Forum

Alter Table to Specify Column Ordering

This is a discussion on Alter Table to Specify Column Ordering within the Oracle Miscellaneous forums, part of the Oracle Database category; --> I am using Oracle. When I define the new tables, I need to add one column at a time ...


Go Back   Unix Technical Forum > Database Server Software > Oracle Database > Oracle Miscellaneous

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-08-2008, 05:25 AM
 
Posts: n/a
Default Alter Table to Specify Column Ordering

I am using Oracle. When I define the new tables, I need to add one column
at a time (or a few columns at a time for large table) using 'alter table
add column_name...'. Is there any way I can modify the ordering of the
columns using the 'alter table' command? Because later on, I have some old
scripts using insert which rely on pre-defined column ordering in table
definition:

insert into table_name
values (...);
-- without explicit column names specified which means the ordering of
columns is important

Thx for advising



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-08-2008, 05:25 AM
Rauf Sarwar
 
Posts: n/a
Default Re: Alter Table to Specify Column Ordering

If you had properly written your insert statements to begin with i.e.
insert into blah (all columns) values (all values); then you would not
be in this predicament.

Even though you can "re-arrange" the ordering of the columns by going
thru few steps.... I would suggest you correct your old scripts and
include column names in the insert statements. This will be a better
solution in the long run.

Regards
/Rauf

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-08-2008, 05:25 AM
Thomas Kyte
 
Posts: n/a
Default Re: Alter Table to Specify Column Ordering

In article <41c69a0b$1_2@rain.i-cable.com>, <tncc> says...
>
>I am using Oracle. When I define the new tables, I need to add one column
>at a time (or a few columns at a time for large table) using 'alter table
>add column_name...'. Is there any way I can modify the ordering of the
>columns using the 'alter table' command? Because later on, I have some old
>scripts using insert which rely on pre-defined column ordering in table
>definition:
>
>insert into table_name
>values (...);
>-- without explicit column names specified which means the ordering of
>columns is important
>
>Thx for advising
>
>
>


as the other person pointed out -- relying on the order of columns like that is
hugely bad. It would be preferable to fix the scripts.

But, you can use views

rename table T to t_table;

create view T as select <columns in whatever order you like> from t_table;

alter table t_table add foobar number;

create or replace view T as select <columns in whatever order you like> from
t_table;


--
Thomas Kyte
Oracle Public Sector
http://asktom.oracle.com/
opinions are my own and may not reflect those of Oracle Corporation
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:31 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com