日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Oracle修改表结构字段名和字段长度

發布時間:2025/3/11 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Oracle修改表结构字段名和字段长度 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

添加字段的語法:alter table tablename add (column datatype [default value][null/not null],….);

修改字段的語法:alter table tablename modify (column datatype [default value][null/not null],….);

刪除字段的語法:alter table tablename drop (column);

創建表結構:
create table test1
(id varchar2(20) not null);

?

增加一個字段:

alter table test1
add (name varchar2(30) default ‘無名氏’ not null);

?

使用一個SQL語句同時添加三個字段:

alter table test1
add (name varchar2(30) default ‘無名氏’ not null,

age integer default 22 not null,

has_money number(9,2)

);

?

修改一個字段

alter table test1
modify (name varchar2(16) default ‘unknown’);

刪除一個字段

alter table test1
drop column name;


Oracle修改表字段名和長度的方式與標準的sql不一樣,它需要增加特定的關鍵字。


使用rename關鍵字來實現字段名的修改:alter table 表名 rename column舊的字段名 to 新的字段名;

alert table wtc rename column qy to qcompany;

使用modify關鍵字來實現對數據類型的修改:alter table 表名 modify 字段名 數據類型;


alert table wtc modify column qcompany varchar2(500);

高級用法:

重命名表
ALTER TABLE
?table_name?RENAME TO?new_table_name;

?

修改列的名稱

語法:
ALTER TABLE table_name RENAME COLUMN supplier_name to sname;

范例:
alter table s_dept rename column age to age1;

?

附:創建帶主鍵的表>>

create table student (
studentid int primary key not null,
studentname varchar(8),
age int);

?

1、創建表的同時創建主鍵約束
(1)無命名
create table student (
studentid int primary key not null,
studentname varchar(8),
age int);
(2)有命名
create table students (
studentid int ,
studentname varchar(8),
age int,
constraint yy primary key(studentid));


2、刪除表中已有的主鍵約束
(1)無命名
可用 SELECT * from user_cons_columns;
查找表中主鍵名稱得student表中的主鍵名為SYS_C002715
alter table student drop constraint SYS_C002715;
(2)有命名
alter table students drop constraint yy;


3、向表中添加主鍵約束
alter table student add constraint pk_student primary key(studentid);



總結

以上是生活随笔為你收集整理的Oracle修改表结构字段名和字段长度的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。