1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Oracleで途中にカラムを追加するのに仮テーブルがいらない方法!

Posted at

Oracle 12c から カラムの要素に visible / invisible が追加されたらしい。

invisible テーブル上には存在するけど見えない
(けど、SQLで直接カラム指定すれば取得できる)
visible invisibleから変更すると見えるようになる
(けど、カラムの順番は最後になる)

これらの特徴を使うと・・・
こんなテーブルがあったとして、

col_a col_b col_e col_d

1.追加したい順番にあるカラム以降を一旦 invisible に変更

Oracle
alter table TABLEA modify (
     col_e invisible
    ,col_d invisible
);

2.新しいカラムを追加

Oracle
alter table TABLEA add ( col_c VARCHAR2(10) );

3.invisible にしたカラム を 変えたい順番で visible に変更

Oracle
alter table TABLEA modify (
     col_d visible
    ,col_e visible
);

のようにすれば、データの移行も不要なので、
従来の別名テーブルを用意しデータを退避したり、大量データのinsertが必要なくなるってことだ!
(∩´∀`)∩わーい♪


【参考URL】

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?