新聞中心
Oracle sql語(yǔ)法
參考網(wǎng)上資料,整理Oracle sql語(yǔ)法:
創(chuàng)新互聯(lián)公司是一家集網(wǎng)站建設(shè),寧洱企業(yè)網(wǎng)站建設(shè),寧洱品牌網(wǎng)站建設(shè),網(wǎng)站定制,寧洱網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營(yíng)銷,網(wǎng)絡(luò)優(yōu)化,寧洱網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競(jìng)爭(zhēng)力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長(zhǎng)自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。
DDL:
1、創(chuàng)建表
?create table?tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..)
?根據(jù)已有的表創(chuàng)建新表:
create table tab_new as select col1,col2… from tab_old
2、刪除表
?drop table?tabname
3、重命名表
?說(shuō)明:alter table?表名?rename to?新表名
? ??eg:alter table tablename?rename to newtablename
4、增加字段
?說(shuō)明:alter table?表名?add?(字段名 字段類型 默認(rèn)值 是否為空);
? ??例:alter table tablename add (ID int);
? ?eg:alter table tablename?add (ID varchar2(30) default '空' not null);
5、修改字段
?說(shuō)明:alter table?表名?modify?(字段名 字段類型 默認(rèn)值 是否為空);
? ??eg:alter table tablename?modify (ID number(4));
6、重名字段
?說(shuō)明:alter table?表名?rename column?列名?to?新列名 (其中:column是關(guān)鍵字)
??eg:alter table tablename?rename column ID to newID;
7、刪除字段
?說(shuō)明:alter table?表名?drop column?字段名;
eg:alter table tablename?drop column ID;
8、添加主鍵
?alter table?tabname?add primary key(col)
9、刪除主鍵
?alter table?tabname?drop primary key(col)
10、創(chuàng)建索引
?create?[unique]?index?idxname on tabname(col….)
11、刪除索引
?drop index?idxname
注:索引是不可更改的,想更改必須刪除重新建。
12、創(chuàng)建視圖
create view?viewname?as select 語(yǔ)句
13、刪除視圖
drop view?viewname
14.????創(chuàng)建表空間
create tablespace schooltbs datafile ‘D:\oracle\datasource\schooltbs.dbf’ size 1000M autoextend on;
15.????刪除表空間
drop tablespace schooltbs[including contents and datafiles];
注:查詢表空間和表空間存儲(chǔ)路徑
SELECT * FROM dba_data_files WHERE tablespace_name = 表空間名;
DML:
1、數(shù)據(jù)查詢
select?列名?from?表名 [where?查詢條件表達(dá)試] [order by?排序的列名[asc或desc]]
2、插入數(shù)據(jù)
insert into?表名?values(所有列的值);
?insert into test values(1,'zhangsan',20);
insert into?表名(列)?values(對(duì)應(yīng)的值);
?insert into test(id,name) values(2,'lisi');
3、更新數(shù)據(jù)
?update?表?set?列=新的值 [where?條件] --更新滿足條件的記錄
?update test set name='zhangsan2' where name='zhangsan'
?update?表?set?列=新的值 --更新所有的數(shù)據(jù)
?update test set age =20;
4、刪除數(shù)據(jù)
delete from?表名?where?條件 --刪除滿足條件的記錄
?delete from test where id = 1;
?delete from test --刪除所有
?commit; --提交數(shù)據(jù)
?rollback; --回滾數(shù)據(jù)
?delete方式可以恢復(fù)刪除的數(shù)據(jù),但是提交了,就沒(méi)辦法了 delete刪除的時(shí)候,會(huì)記錄日志 --刪除會(huì)很慢很慢
truncate table?表名
?刪除所有數(shù)據(jù),不會(huì)影響表結(jié)構(gòu),不會(huì)記錄日志,數(shù)據(jù)不能恢復(fù) --刪除很快
drop table?表名
?刪除所有數(shù)據(jù),包括表結(jié)構(gòu)一并刪除,不會(huì)記錄日志,數(shù)據(jù)不能恢復(fù)--刪除很快
5、數(shù)據(jù)復(fù)制
表數(shù)據(jù)復(fù)制
insert into?table1 (select?*?from?table2);
復(fù)制表結(jié)構(gòu)
create table?table1?select * from?table2?where?11;
復(fù)制表結(jié)構(gòu)和數(shù)據(jù)
?create table?table1?select * from?table2;
復(fù)制指定字段
?create table?table1?as select?id, name?from?table2?where?11;
Oracle 聯(lián)合主鍵批量刪除
例如我的表A中唯一約束(或者主鍵)為B,我要?jiǎng)h除B的值為c,d,e的行那么可以執(zhí)行:delete from a where b in ('c','d','e');擁有唯一性約束的表的確是比較容易進(jìn)行判斷和刪除的。當(dāng)然了我還可以使用外部條件如,delete from a where b in (select c from d where e ='xx');這就是刪除了a表中的行,判斷條件是b的值從d表的c列中??;c列的判斷條件是,d表中e列的值為xx。
oracle數(shù)據(jù)庫(kù)主鍵可以刪除嗎
可以刪除。但不建議刪除。設(shè)置為主鍵一定是有原因的,先了解清楚列被設(shè)置為主鍵的原因再說(shuō)。
主鍵約束如何刪除??
你可以把表刪了,在創(chuàng)建沒(méi)主鍵約束的表就可以了;或者是你創(chuàng)建約束時(shí)指定約束名
例:create table t_stu(stuid integer not null,stuname varchar(50))
添加主鍵alter table t_stu add constraint p_pk priary key stuid;p_pk是約束名字
刪除主鍵:alter table t_stu drop constraint p_pk,從你的錯(cuò)務(wù)信息可以看出你沒(méi)有給約束起名字吧。
oracle如何刪除主外鍵來(lái)修改字段類型
主鍵不需要?jiǎng)h除。
刪除、增加外鍵,請(qǐng)查閱ALTER TABLE的語(yǔ)法。
分享名稱:oracle如何刪除主健,怎么刪除Oracle
文章出自:http://fisionsoft.com.cn/article/hcdooe.html