SQL优化笔记

1.oracle 修改某列属性
alter table ttt modify ccc NUMBER(10) NULL;
2.特殊情况,需要用sql查询表的主键
3.设置某一列的默认值 Alter table 表名 modify 列名 default ‘AAA’
4.应尽量避免在 where 子句中使用 or 来连接条件,否则将导致引擎放弃使用索引而进行全表扫描,如:
select id from t where num=10 or num=20
可以这样查询:
select id from t where num=10
union all
select id from t where num=20

1.查询所有没有主键的表

select table_name
  from user_tables a
 where not exists (select *
          from user_constraints b
         where b.constraint_type = 'P'
           and a.table_name = b.table_name)

1.查看所有的函数和存储过程
select name from user_source where type='PROCEDURE' group by name;
select name from user_source where type='FUNCTION' group by name; 

1,PL/SQL看执行计划,看时间Cost
2.检索条件 加索引,加快查询速度
3.优化器,
推荐工具: Tosska SQL Tuning Expert 分32位64位,
https://www.cnblogs.com/dbexpert/p/9045767.html
本质就是利用Oracle的hint功能,指定执行计划
4.表连接的访问方法

union all 不去重复数据
union会去除重复数据
union与join的区别
join有连接条件,union是把结果一起显示(条件是列相同,类型相同)

4. oracle怎么查询所有的表空间的名称?
select tablespace_name  from user_tablespaces;



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值