How To Add a New Column to an Existing Table?
Page 1 of 1
How To Add a New Column to an Existing Table?
If you have an existing table with existing data rows, and want to add a new column to that table,
you can use the ALTER TABLE ... ADD statement to do this. Here is an example script:
SQL> connect HR/fyicenter
Connected.
SQL> CREATE TABLE emp_dept_110
2 AS SELECT * FROM employees WHERE department_id=110;
Table created.
SQL> ALTER TABLE emp_dept_110 ADD (vacation NUMBER);
Table altered.
SQL> SELECT first_name, last_name, vacation FROM emp_dept_110;
FIRST_NAME LAST_NAME VACATION
-------------------- ------------------------- ----------
Shelley Higgins
William Gietz
This SQL script added a new column called "vacation" to the "emp_dept_110" table. NULL values
were added to this column on all existing data rows.
you can use the ALTER TABLE ... ADD statement to do this. Here is an example script:
SQL> connect HR/fyicenter
Connected.
SQL> CREATE TABLE emp_dept_110
2 AS SELECT * FROM employees WHERE department_id=110;
Table created.
SQL> ALTER TABLE emp_dept_110 ADD (vacation NUMBER);
Table altered.
SQL> SELECT first_name, last_name, vacation FROM emp_dept_110;
FIRST_NAME LAST_NAME VACATION
-------------------- ------------------------- ----------
Shelley Higgins
William Gietz
This SQL script added a new column called "vacation" to the "emp_dept_110" table. NULL values
were added to this column on all existing data rows.
Similar topics
» How To Add a New Column to an Existing Table?
» How To Delete a Column in an Existing Table?
» How To Add a New Column to an Existing Table with a Default Value?
» How To Rename a Column in an Existing Table?
» How To Delete a Column in an Existing Table?
» How To Delete a Column in an Existing Table?
» How To Add a New Column to an Existing Table with a Default Value?
» How To Rename a Column in an Existing Table?
» How To Delete a Column in an Existing Table?
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
Sun Jan 31, 2010 12:35 am by Micheal
» Accessing tables of other users in SQL
Sun Jan 31, 2010 12:34 am by Micheal
» Grouping commands in SQL
Sun Jan 31, 2010 12:32 am by Micheal
» Operations on Result Sets in SQL
Sun Jan 31, 2010 12:31 am by Micheal
» Subqueries in SQL
Sun Jan 31, 2010 12:30 am by Micheal
» Joining Relations in SQL
Sun Jan 31, 2010 12:28 am by Micheal
» Delete comand in SQL
Sun Jan 31, 2010 12:27 am by Micheal
» Update command in SQL
Sun Jan 31, 2010 12:26 am by Micheal
» Insert command in SQL
Sun Jan 31, 2010 12:23 am by Micheal