oracle, ddl, dml,索引

DDL     
create table 创建表
alter table 修改表
drop table 删除表
truncate table 删除表中所有行
create index 创建索引
drop index 删除索引
当执行DDL语句时,在每一条语句前后,oracle都将提交当前的事务。如果用户使用insert命令将记录插入到数据库后,执行了一条DDL语句(如create table),此时来自insert命令的数据将被提交到数据库。当DDL语句执行完成时,DDL语句会被自动提交,不能回滚。

DML
insert 将记录插入到数据库
update 修改数据库的记录
delete 删除数据库的记录

当执行DML命令如果没有提交,将不会被其他会话看到。除非在DML命令之后执行了DDL命令或DCL命令,或用户退出会话,或终止实例,此时系统会自动发出commit命令,使未提交的DML命令提交。

alter  1.添加列 alter table talb_name  add col_name datatype [default val] [ not null ] [constraint...] 2.删除列 alter table tale_name drop column col_name; 3.修改列: alter table tale_name modify...... 原则: 1,可以扩大列的宽度 2.减少列的宽度,保证列里边的值为null,或者表中么有记录 3.默认值只会对后续操作产生影响 4.要修改为not null约束,必须保证这个列的值没有null值。 5.如果需要修改列的数据类型,要保证当前列值为null 4.添加约束 alter table ta_name add 约束定义 5.删除约束 alter table ta_name drop constaint 约束名字 alter table ta_name drop primary key cascade; 6.使约束失效 alter table table_name disable constraint 约束名字 7.使 生效 alter table table_name enable constraint 约束名字

表结构的修改:(这些也属于DDL语句) alter 在表中添加一个新的列 alter table test add birthday date; 删除表的某列 alter table test drop column birthday; 给表中的列添加约束 //这个约束相当于之前的表级约束 alter table test add constraint test_name_un unique(name); insert into test(id,name) values(1,'zs'); insert into test(id,name) values(2,'zs'); 删除表中的约束 alter table test drop constraint test_name_un; insert into test(id,name) values(1,'zs'); insert into test(id,name) values(2,'zs'); 修改表的名字: rename test to mytest; 修改表中某列的类型 alter table test modify (name varchar2(500)); 让约束失效: 必须知道约束的名字 alter table s_emp disable constraint s_emp_id_pk cascade; 让失效的约束再次生效 alter table s_emp enable constraint s_emp_id_pk; //截断表中的数据(删除),不需要提交,默认已经提交,并且不能回滚 truncate table test; 相当于: delete from test; commit; //给表添加注释 comment on table test is '很好'; //给列添加注释 comment on column test.name is 'good'; //查看表中注释 select * from user_tab_comments where table_name='TEST'; //查看中的注释 select * from user_col_comments where comments is not null and table_name='TEST';

index索引 作用:提高在表查询数据的效率 由数据库系统自行维护 index是建立在列上面的 条件: 1.这个列中的数据会经常被用做查询数据的条件 2.这个列上的数据不会经常的改动 注意: 1.有主键约束的列或者是有唯一性约束的列上面系统会默认的加上索引. 2.在一个表中,索引并非是越多越好。 3.在表中的某一个合适的列加入上了索引,那么也只有在数据量很大的时候,才能有所体现出这个查询的效率. 4.索引一旦建立成功,那么之后这个索引就由系统来管理,我们自己是控制不了的. 索引的种类: B-tree 位图 反序 函数 建立索引的格式: create index 索引名 on 表名(列名); create index emp_index on s_emp(last_name); 删除索引 drop index 索引名; drop index emp_index;

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值