4. Managing Tables and Views : Table Management : Techniques for Changing Table Columns : Example: Rename a Column
 
Share this page                  
Example: Rename a Column
The following example renames two columns, name and addr, to employee and address. The salary column is not renamed.
Using SQL:
1. Create a temporary table with all columns from the original table, renaming the desired columns. For example:
create table temp as
select name as employee, addr as address, salary
from test;
2. Drop the original table:
drop test;
3. Re-create the original table with the columns from the temporary table:
create table test as
select * from temp;
4. Drop the temporary table:
drop temp;
In VDBA, follow these steps to rename such columns:
1. Assuming the table test already exists with columns name, addr, and salary, create a temporary table named temp.
2. Enable Create Table As Select in the Create Table dialog.
3. In the Select Statement edit control, enter the following select statement to rename the desired columns:
select name as employee, addr as address, salary
    from test
4. Drop the original table, test.
5. Create a new table named test.
6. Enable Create Table As Select in the Create Table dialog.
7. In the Select Statement edit control, enter:
select * from temp
8. Drop the temporary table, temp.
Be sure to update any objects, such as reports, forms, and programs that are dependent on the old column name, and recreate integrities, views, indexes, grants, and other dependent objects that were destroyed when the original table was dropped.