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 ?
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 ?
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!"
>>what is table mutation error and what is the occation it will happen
Follow the link
eg:-alter table emp add email_add varchar2(15);
this will insert the column email_add to your table.
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
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.
Alter table tablename add(columnname datatype).With this command u can add the column.
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';
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 06:19 AM.
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
Alter table dept
add (ename varchar2(10));
For insert the value in ename colomn,
Insert into dept (ename)
value('Deepa');
Try this. I think you will getting u r answer.
1. Command for add a new column name emp_email
A. Syntax:
ALTER TABLE
ADD;
B. Command
ALTER TABLE emp
ADD emp_email varchar2(40);
2. To add values to this column
A. Syntax
UPDATE
SET= <'Value'>
WHERE= <'value'>;
B. Example:
UPDATE emp
SET emp_email = 'emp_smith@yahoo.com'
WHERE ename = 'SMITH';