1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ORACLE:列の追加・削除・変更

Last updated at Posted at 2020-05-21

列の追加

ALTER TABLE Table名 ADD column

例)table_Aに下記の2種類のカラムを追加
 column_1:VARCHAR2(200 byte)型で、NOT NULL制約を付与
 column_2:NUMBER型で有効数字3桁

ALTER TABLE table_A ADD (
    column_1 VARCHAR2(200 byte) NOT NULL ,
    column_2 NUMBER(*,0)
);

※NUMBER型の補足
NUMBER (precision, scale)

・任意で**precision(精度。全体の桁数)スケール(小数点以下の桁数)**が指定可能。
例)NUMBER(*,0)
 精度:38(最大値)
 スケール:整数

カラムの削除

ALTER TABLE Table名 DROP

例)table_Aからcolumn_1, column_2を削除

ALTER TABLE table_A DROP (
    column_1, column_2
)

列名の変更

ALTER TABLE テーブル名 RENAME COLUMN 変更前 TO 変更後;

データ型変更

ALTER TABLE テーブル MODIFY (列の定義);
例:
ALTER TABLE table1 MODIFY (CODE VARCHAR2(10));
ALTER TABLE table2 MODIFY (CODE NUMBER);
1
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?