Prepare for your Next Interview
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 ...
|
|||
|
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 ? |
| The Following User Says Thank You to Ajit Kumar Maharatha For This Useful Post: | ||
| Sponsored Links |
|
|||
|
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!" |
|
|||
|
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. |
|
|||
|
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
|
|
|||
|
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. |
|
|||
|
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.
|
| The Following User Says Thank You to susarlasireesha For This Useful Post: | ||
|
|||
|
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'; |
|
|||
|
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. |
|
|||
|
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 |
|
|||
|
Re: Add a new column to a table and insert values
Quote:
|
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| 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 |