国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

首頁 php教程 PHP開發(fā) oracle刪除表字段和oracle表增加字段

oracle刪除表字段和oracle表增加字段

Jan 06, 2017 am 10:52 AM

添加字段的語法: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);

添加、修改、刪除多列的話,用逗號隔開。

使用alter table 來增加、刪除和修改一個列的例子。

創(chuàng)建表結(jié)構(gòu):
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');

另:比較正規(guī)的寫法是:

-- Add/modify columns 
alter table TABLE_NAME rename column FIELD_NAME to NEW_FIELD_NAME;

刪除一個字段

alter table test1
drop column name;

需要注意的是如果某一列中已經(jīng)存在值,如果你要修改的為比這些值還要小的列寬這樣將會出現(xiàn)一個錯誤。

例如前面如果我們插入一個值

insert into test1
values ('1′,'我們很愛你');

然后曾修改列: alter table test1
modify (name varchar2(8));
將會得到以下錯誤:
ERROR 位于第 2 行:
ORA-01441: 無法減小列長度, 因為一些值過大

高級用法:

重命名表
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;


附:創(chuàng)建帶主鍵的表>>

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

1、創(chuàng)建表的同時創(chuàng)建主鍵約束
(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刪除表字段和oracle表增加字段相關(guān)文章請關(guān)注PHP中文網(wǎng)!

本站聲明
本文內(nèi)容由網(wǎng)友自發(fā)貢獻(xiàn),版權(quán)歸原作者所有,本站不承擔(dān)相應(yīng)法律責(zé)任。如您發(fā)現(xiàn)有涉嫌抄襲侵權(quán)的內(nèi)容,請聯(lián)系admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費(fèi)脫衣服圖片

Undresser.AI Undress

Undresser.AI Undress

人工智能驅(qū)動的應(yīng)用程序,用于創(chuàng)建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用于從照片中去除衣服的在線人工智能工具。

Clothoff.io

Clothoff.io

AI脫衣機(jī)

Video Face Swap

Video Face Swap

使用我們完全免費(fèi)的人工智能換臉工具輕松在任何視頻中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費(fèi)的代碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

功能強(qiáng)大的PHP集成開發(fā)環(huán)境

Dreamweaver CS6

Dreamweaver CS6

視覺化網(wǎng)頁開發(fā)工具

SublimeText3 Mac版

SublimeText3 Mac版

神級代碼編輯軟件(SublimeText3)