oracle 表結構的修改

2021-05-17 18:18:34 字數 1528 閱讀 2310

更改表的結構

1.編輯表的字段

修改乙個列的資料型別(一般限於修改長度,修改為乙個不同型別時有諸多限制):

語法:alter table 表名 modify(列名 資料型別);

eg1:

alter table skate_test modify (author number(10,0) )

在修改列的長度時候,只能編輯比現有字段實際存的長度還要大,否則提示下面的錯誤:

ora-01441: 無法減小列長度, 因為一些值過大

eg2:

alter table skate_test modify (author varchar2(10) )

在修改列的資料型別的時候,所修改的列必須為空,否則提示下面的錯誤:

ora-01439: 要更改資料型別, 則要修改的列必須為空

2.增加乙個列

語法:alter table 表名 add(列名 資料型別);

eg1:

alter table skate_test add(author number(38,0) not null);

3.給列改名:

語法:alter table 表名 rename column 當前列名 to 新列名;

eg1:

alter table skate_test rename column author to authorer_new

4.刪除乙個列

語法:alter table 表名 drop column 列名;

eg1:

alter table skate_test drop column author

5.將乙個表改名

語法:alter table 當前表名 rename to 新錶名;

eg1:

alter table skate_test rename to test_sakte

5.給表加注釋

comment column on 表名.列名 is '注釋內容';   //修改表的列的注釋

comment on table movo_new.test_sakte  is '注釋內容';  //修改表的注釋

--- 待續---

alter 語句修改資料表

1.修改資料表名

alter table [方案名.]old_table_name rename to new_table_name;

2.修改列名

alter table [方案名.]table_name rename column old_column_name to new_column_name;

3.修改列的資料型別

alter table [方案名.]table_name modify column_name new_datatype;

4.插入列

alter table [方案名.]table_name add column_name datatype;

5.刪除列

alter table [方案名.]table_name drop column column_name;

oracle 修改表結構

增加表字段 alter table 表名 add age number 3 alter table 表名 add varchar2 10 default 男 alter table 表名 add photo varchar2 100 default nophoto.jpg 修改表字段 alter t...

Oracle修改表結構

alter table table add column datatype default expr column datatype alter table table modify column datatype default expr column datatype alter table t...

Oracle修改表結構

1.修改欄位的資料型別 語法 alter table 表名 modify 列名 資料型別 eg1 alter table emp modify column1 varchar 10 在修改列的長度時候,只能編輯比現有字段實際存的長度還要大,否則提示下面的錯誤 ora 01441 無法減小列長度,因為...