Results 1 to 13 of 13

Thread: Add a new column to a table and insert values

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    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 ?


  2. #2
    Expert Member
    Join Date
    Sep 2006
    Answers
    477

    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!"

  3. #3
    Junior Member
    Join Date
    Oct 2008
    Answers
    1

    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


  4. #4
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    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


  5. #5

    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.


  6. #6
    Junior Member
    Join Date
    Oct 2007
    Answers
    2

    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


  7. #7
    Moderator
    Join Date
    Jun 2007
    Answers
    2,074

    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.


  8. #8
    Expert Member
    Join Date
    Apr 2007
    Answers
    500

    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.


  9. #9
    Junior Member
    Join Date
    Sep 2008
    Answers
    18

    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';


  10. #10

    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 06:19 AM.

  11. #11
    Junior Member
    Join Date
    Oct 2008
    Answers
    28

    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


  12. #12
    Junior Member
    Join Date
    Oct 2008
    Answers
    11

    Re: Add a new column to a table and insert values

    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.


  13. #13
    Junior Member
    Join Date
    Sep 2010
    Answers
    1

    Re: Add a new column to a table and insert values

    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';


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •  
    About us
    Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
    Interact