Geeks Talk

Prepare for your Next Interview




Insert new column in the middle of a table

This is a discussion on Insert new column in the middle of a table within the SQL forums, part of the Databases category; Question asked by visitor kiran Can I insert a new column in the middle of an existing table? Say I have created a table emp in order -> eno, ename, jobnow ...


Go Back   Geeks Talk > Databases > SQL

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 04-15-2007
Expert Member
 
Join Date: Feb 2007
Posts: 1,279
Thanks: 0
Thanked 161 Times in 137 Posts
Geek_Guest is on a distinguished roadGeek_Guest is on a distinguished road
Insert new column in the middle of a table

Question asked by visitor kiran

Can I insert a new column in the middle of an existing table?
Say I have created a table emp in order -> eno, ename, jobnow I want to insert a new column in between ename and job. If posble how?
Reply With Quote
The Following User Says Thank You to Geek_Guest For This Useful Post:
Sponsored Links
  #2 (permalink)  
Old 04-18-2007
Expert Member
 
Join Date: Jun 2006
Location: India
Posts: 411
Thanks: 15
Thanked 33 Times in 25 Posts
jamesravid is on a distinguished road
Re: Insert new column in the middle of a table

In oracle, you can't do that. Between why do u need this? insert a new column in the middle of a table is not going to make any difference than appending a new column at the end.

could you tell us why you need this?
__________________
Cheers,
:) James:)
Reply With Quote
  #3 (permalink)  
Old 04-23-2007
Moderator
 
Join Date: Sep 2006
Location: Delhi (India)
Posts: 864
Thanks: 12
Thanked 81 Times in 65 Posts
jainbrijesh is on a distinguished road
Re: Insert new column in the middle of a table

You can add that in the end, but can view that in middle using sql select statement by changing the sequence of columns as per your requirement.
__________________
Brijesh Jain
brijesh.tester@yahoo.co.in
http://softwaretestingexpertise.blogspot.com

Last edited by jainbrijesh : 04-23-2007 at 02:01 AM.
Reply With Quote
The Following User Says Thank You to jainbrijesh For This Useful Post:
  #4 (permalink)  
Old 04-23-2007
Junior Member
 
Join Date: Feb 2007
Location: Bangalore
Posts: 17
Thanks: 0
Thanked 1 Time in 1 Post
jbanx is on a distinguished road
Re: Insert new column in the middle of a table

You can't do it but what you can do it is add at the end of the table with alter table add column statement !!!
Reply With Quote
  #5 (permalink)  
Old 07-09-2007
Moderator
 
Join Date: Jun 2007
Location: Bangalore,India
Posts: 1,365
Thanks: 7
Thanked 123 Times in 111 Posts
debasisdas will become famous soon enoughdebasisdas will become famous soon enough
Re: Insert new column in the middle of a table

That is not supported in oracle ,at least till version 10.2.0.

Actually it does not have any effect on data retrival and presentataion.
Reply With Quote
  #6 (permalink)  
Old 08-06-2007
Junior Member
 
Join Date: Jun 2007
Location: Bangalore
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
soorajsk_84 is on a distinguished road
Re: Insert new column in the middle of a table

No u cannot insert a new column in middle of table but to the last is possible with a alter command
Reply With Quote
  #7 (permalink)  
Old 07-07-2008
Junior Member
 
Join Date: Jun 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
kutty9585 is on a distinguished road
Re: Insert new column in the middle of a table

i too have the same problem can anybody sort it out
Reply With Quote
  #8 (permalink)  
Old 07-07-2008
Junior Member
 
Join Date: Jul 2008
Location: mumbai
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
pothilal is on a distinguished road
Re: Insert new column in the middle of a table

You can add a new column in the end, not in the middle.
inserting a new column in the middle of a table is not going to make any difference than appending a new column at the end.You can view that in middle using sql select statement by changing the sequence of columns as per your requirement.
Reply With Quote
  #9 (permalink)  
Old 07-08-2008
Contributing Member
 
Join Date: Sep 2007
Location: hyderabad
Posts: 36
Thanks: 5
Thanked 2 Times in 2 Posts
ashalalaxmi2002 is on a distinguished road
Re: Insert new column in the middle of a table

you cannot insert column in the middle of the table.if u add any column to table it will appended to end.
if u want to appear in the middle, create another table by selecting columns from that table.
Reply With Quote
  #10 (permalink)  
Old 07-08-2008
Moderator
 
Join Date: Jun 2007
Location: Bangalore,India
Posts: 1,365
Thanks: 7
Thanked 123 Times in 111 Posts
debasisdas will become famous soon enoughdebasisdas will become famous soon enough
Re: Insert new column in the middle of a table

Quote:
Originally Posted by kutty9585 View Post
i too have the same problem can anybody sort it out
Have you gone through the previous posts ?
Reply With Quote
  #11 (permalink)  
Old 07-09-2008
Junior Member
 
Join Date: Jun 2008
Location: Lebanon
Posts: 12
Thanks: 1
Thanked 2 Times in 2 Posts
ronaldrahme is on a distinguished road
Re: Insert new column in the middle of a table

yeah sure u can insert a new column in the middle, unfortunately it cannot be done by script, you can do it manually.
after you create the new column, open the design table, your column appears at the end, at the most left of the table, click on the column where an arrow appears, click on the arrow and place up the column where you want.
hope it helps.
Reply With Quote
The Following User Says Thank You to ronaldrahme For This Useful Post:
  #12 (permalink)  
Old 07-11-2008
Junior Member
 
Join Date: Jun 2008
Location: pune
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
suraz is on a distinguished road
Re: Insert new column in the middle of a table

U can't insert a new column in the middle of the table.
Oracle by default, any new column that inserted be at the end of the table.
Reply With Quote
  #13 (permalink)  
Old 07-17-2008
Junior Member
 
Join Date: Mar 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
csbhaskar is on a distinguished road
Re: Insert new column in the middle of a table

the position of a column in an oracle table does not carry much value. The only problem is while selecting the columns with * the order will be not the desired one. however, this is till not solved by oracle.
We have to bear with it or the other option is to write the comple name list in desired order while selecting.
Reply With Quote
  #14 (permalink)  
Old 07-17-2008
Junior Member
 
Join Date: Jul 2008
Location: chennai
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
pandubujji is on a distinguished road
Re: Insert new column in the middle of a table

No we can not insert a new clumn in the middle of a table
Reply With Quote
  #15 (permalink)  
Old 07-17-2008
Moderator
 
Join Date: Jun 2007
Location: Bangalore,India
Posts: 1,365
Thanks: 7
Thanked 123 Times in 111 Posts
debasisdas will become famous soon enoughdebasisdas will become famous soon enough
Re: Insert new column in the middle of a table

Quote:
Originally Posted by ronaldrahme View Post
yeah sure u can insert a new column in the middle, unfortunately it cannot be done by script, you can do it manually.
after you create the new column, open the design table, your column appears at the end, at the most left of the table, click on the column where an arrow appears, click on the arrow and place up the column where you want.
hope it helps.

what design table you are talking about ?
Reply With Quote
  #16 (permalink)  
Old 07-17-2008
Junior Member
 
Join Date: Apr 2008
Location: Hyderabad
Posts: 24
Thanks: 1
Thanked 4 Times in 2 Posts
nageshkota is on a distinguished road
Re: Insert new column in the middle of a table

It is not possible to insert a column in the middle of the table, But there is one way to do that in Oracle and SQL Server also. you can insert the column at the end and create a temp table in the reqired format and move the data from the original table to new table and replace the new file name with the old file name. By this way we can insert the column in the middle.
Hope it will help for you.
Reply With Quote
  #17 (permalink)  
Old 08-27-2008
Junior Member
 
Join Date: Aug 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
psundarus is on a distinguished road
Re: Insert new column in the middle of a table

Yes, that is possible. Try with this

1. Create a new table and copy the data across.

SQL> RENAME tab1 TO tab1_old;
Table renamed.

SQL> CREATE TABLE tab1 AS SELECT 0 AS col1, col1 AS col2 FROM tab1_old;
Table created

Also please visit this site orafaq . com/wiki/SQL_FAQ
Reply With Quote
  #18 (permalink)  
Old 3 Weeks Ago
Junior Member
 
Join Date: Jan 2008
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
chaitueeturi is on a distinguished road
Re: Insert new column in the middle of a table

That is not possible in oracle.But u can try the following

Just u create a view on that particular table and keep the order of the columns in your view as you required.And use that view when ever you have to work on your table.Using view means You are indirectly working on ur original table.
Reply With Quote
  #19 (permalink)