Geeks Talk

Prepare for your Next Interview




Add a new column to a table and insert values

This is a discussion on Add a new column to a table and insert values within the Oracle forums, part of the Databases category; How can i add a new column to a table and insert values in that column which will be beside the previous column? like suppose i want to add a ...


Go Back   Geeks Talk > Databases > Oracle

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 02-10-2007
Junior Member
 
Join Date: Jan 2007
Location: hyderabad
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post
Ajit Kumar Maharatha is on a distinguished road
Add a new column to a table and insert values

How can i add a new column to a table and insert values in that column
which will be beside the previous column? like suppose i want to add a email address column to emp table and add email address of smith who is already a member of emp table ?
Reply With Quote
The Following User Says Thank You to Ajit Kumar Maharatha For This Useful Post:
Sponsored Links
  #2 (permalink)  
Old 02-10-2007
Expert Member
 
Join Date: Sep 2006
Location: Bengalooru (Formerly called Bangalore), India
Posts: 486
Thanks: 2
Thanked 28 Times in 27 Posts
kalayama is on a distinguished road
Re: Add a new column to a table and insert values

It is simple task as long as your new column allows NULLs.
Take a back up of existing table and then go on to add the column.

select * intoo emp_backup from emp.

ALTER TABLE EMP
ADD emp_email varchar2(40);

This will add the column emp_email to emp table.

Now to add a value to this column, you should use UPDATE statement. Simple as that.

Cheers!
Kalayama
__________________
[COLOR="Blue"][SIZE="2"]"If you are not living on the edge of your life, you are wasting space"[/SIZE][/COLOR]

Someone says "Impossible is nothing". The man next him says "Let me see you licking your elbow tip!"
Reply With Quote
  #3 (permalink)  
Old 09-04-2007
Junior Member
 
Join Date: Feb 2007
Location: pulivendula,kadapa(district),a.p,india
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
yagnam ramesh babu is on a distinguished road
Re: Add a new column to a table and insert values

eg:-alter table emp add email_add varchar2(15);
this will insert the column email_add to your table.
Reply With Quote
  #4 (permalink)  
Old 10-08-2007
Junior Member
 
Join Date: Oct 2007
Location: hyderabad
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
niranjanareddy is on a distinguished road
Re: Add a new column to a table and insert values

Alter table emp add email_address varchar(30); --this will creates a column email_address. After creating column,update the table to insert the email address of the smith. I.e., update emp set email_address=' ' where ename='smith'; ok....bye... Kalayama
Reply With Quote
  #5 (permalink)  
Old 10-08-2007
Moderator
 
Join Date: Jun 2007
Location: Bangalore,India
Posts: 1,426
Thanks: 8
Thanked 125 Times in 112 Posts
debasisdas will become famous soon enoughdebasisdas will become famous soon enough
Re: Add a new column to a table and insert values

You need to execute 2 separate commands.
1. alter (DDL) table to add a new field to existing table.
2.Update (DML) the table to insert value to the new column.
Reply With Quote
  #6 (permalink)  
Old 10-09-2007
Expert Member
 
Join Date: Apr 2007
Location: Bangalore
Posts: 441
Thanks: 19
Thanked 54 Times in 54 Posts
susarlasireesha is on a distinguished road
Re: Add a new column to a table and insert values

Alter table tablename add(columnname datatype).With this command u can add the column.
Reply With Quote
The Following User Says Thank You to susarlasireesha For This Useful Post:
  #7 (permalink)  
Old 09-21-2008
Junior Member
 
Join Date: Sep 2008
Location: NOIDA
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
aditi14 is on a distinguished road
Re: Add a new column to a table and insert values

For add new col you need alter command
SQL>alter table emp add (email varchar2(30));
For insert the value in this col according condition
SQL>update emp set email='gmail' where name='scott';
Reply With Quote
  #8 (permalink)  
Old 10-04-2008
Junior Member
 
Join Date: Oct 2008
Location: AHMEDABAD
Posts: 6
Thanks: 0
Thanked 1 Time in 1 Post
sunshine60india is on a distinguished road
Re: Add a new column to a table and insert values

For adding column to the table...
ALTER TABLE table-name ADD column-name type(size);

For inserting data into added column
UPDATE table-name SET column-name =value WHERE condition;

Thanks,, Vipul Patel

Last edited by sunshine60india : 10-04-2008 at 07:19 AM.
Reply With Quote
  #9 (permalink)  
Old 10-07-2008
Junior Member
 
Join Date: Oct 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
nehrumosuru is on a distinguished road
Re: Add a new column to a table and insert values

The following commands used for adding new column and inserting values to the table.

1. For adding column to the table

ALTER TABLE emp
ADD ( EMP_NAME VARCHAR(30));

2. For inserting data into table

INSERT INTO emp(NAME)
VALUES ('VINAYAKA')

Regards

Nehru Mosuru
Reply With Quote
  #10 (permalink)  
Old 10-09-2008
Junior Member
 
Join Date: Oct 2008
Location: Hyderabad
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
denniscodd is on a distinguished road
Re: Add a new column to a table and insert values

Quote:
Originally Posted by kalayama View Post
It is simple task as long as your new column allows NULLs.
Take a back up of existing table and then go on to add the column.

select * intoo emp_backup from emp.

ALTER TABLE EMP
ADD emp_email varchar2(40);

This will add the column emp_email to emp table.

Now to add a value to this column, you should use UPDATE statement. Simple as that.

Cheers!
Kalayama
what is table mutation error and what is the occation it will happen
Reply With Quote
  #11 (permalink)  
Old 10-10-2008
Expert Member
 
Join Date: Sep 2007
Posts: 754
Thanks: 22
Thanked 64 Times in 63 Posts
krishnaindia2007 is on a distinguished road
Re: Add a new column to a table and insert values

>>what is table mutation error and what is the occation it will happen

Follow the link
Reply With Quote
Reply

  Geeks Talk > Databases > Oracle

« wrap | Joins »

Thread Tools
Display Modes


Similar Threads

Thread Thread Starter Forum Replies Last Post
Column to row transformation JobHelper Data Warehousing 2 01-18-2008 08:27 AM
Displaying data in a DataGrid for particular column JobHelper ASP.NET 1 02-26-2007 10:58 PM
Finding exact mismatched column name JobHelper Data Warehousing 1 01-25-2007 03:51 AM
Picklist values are coming from S_LST_VAL table JobHelper Seibel 3 01-13-2007 03:10 AM
Compare values of column in a table JobHelper SQL Server 1 12-13-2006 01:57 AM


All times are GMT -4. The time now is 11:44 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Copyright © 2008 GeekInterview.com. All Rights Reserved