Another way to rename a column is to use the RENAME statement together with the
CREATE TABLE statement with AS subquery. This method is useful if you are
changing the structure of a table rather than only renaming a column. The
following statements re-create the sample table hr.job_history, renaming a column from
department_id to dept_id:
CREATE TABLE temporary
(employee_id, start_date, end_date, job_id, dept_id)
AS SELECT
employee_id, start_date, end_date, job_id, department_id
FROM job_history;
DROP TABLE job_history;
RENAME temporary TO job_history;
Any integrity constraints defined on table job_history will be lost in the
preceding example. You will have to redefine them on the new job_history table using an
ALTER TABLE statement.[@more@]
CREATE TABLE statement with AS subquery. This method is useful if you are
changing the structure of a table rather than only renaming a column. The
following statements re-create the sample table hr.job_history, renaming a column from
department_id to dept_id:
CREATE TABLE temporary
(employee_id, start_date, end_date, job_id, dept_id)
AS SELECT
employee_id, start_date, end_date, job_id, department_id
FROM job_history;
DROP TABLE job_history;
RENAME temporary TO job_history;
Any integrity constraints defined on table job_history will be lost in the
preceding example. You will have to redefine them on the new job_history table using an
ALTER TABLE statement.[@more@]
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10599713/viewspace-978047/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/10599713/viewspace-978047/
本文介绍了一种通过结合RENAME和CREATE TABLE语句来改变表结构的方法,特别是如何将表hr.job_history中的一列从department_id重命名为dept_id的过程。此方法不仅限于重命名列,还适用于更广泛的表结构调整。
16

被折叠的 条评论
为什么被折叠?



