SQl Cookbook学习笔记
1.select * from A where a.a='a';
执行顺序 先执行 from 在执行 where 中的东西 ,最后执行 select
2.列值连接 db2 oracle || , mysql concat(column1,'sss',column2) sqlServler使用+连接;
3. case when 表达式 then ''
when 表达式 then ''
else ''
end
4. 限制返回的行数
在oracle中使用rownum <= n 限制行数
在db2中使用fetch first 5 rows only
注意 oracle中如果使用rownum =5 是得不到第五行的,因为oracle的查询原理获取一行后赋给行号,如果行号满足条件返回否则舍弃,这样永远得不到第五行,永远是第一行号并接舍弃,所以要想得到第五行,必须得到前四行,所以查询前五行必须是<= 5;
5.null 要想判断值是否为null必须为 is null , null不能用等于=和不等于<> 和任何值比较包括null
6。按模式查询 like '%a'
相关文档:
1.查询连接到某数据库的连接数
select count(*) as 连接数 from master..sysprocesses where db_name(dbid)='数据库名' ......
查询速度慢的原因很多,常见如下几种:
1、没有索引或者没有用到索引(这是查询慢最常见的问题,是程序设计的缺陷)
2、I/O吞吐量小,形成了瓶颈效应。
3、没有创建计算列导致查询不优化。
4、内存不足
5、网络速度慢
6、查询出的数据量过大(可以采用多次查询,其他的方法降低数据量)
7、 ......
List<Class1> li = dc.Table_1.Where(item => item.id > 1).Cast<Class1>().ToList();
Table_1 为自动生成类, class1为自定义类,属性名称都是一样的,要能实现上面的语句,必须有几个条件
Table_1 需要继承class1,可以通过partial类来实现
Table_1 属性加override
class1里面的属性要是vir ......
Tuning an Application / Reducing Load
If your whole application is performing suboptimally, or if you are attempting to
reduce the overall CPU or I/O load on the database server, then identifying
resource-intensive SQL involves the following steps:
1. Determine which period in the day you would ......
基于索引的SQL语句优化之降龙十八掌
1 前言
客服业务受到SQL语句的影响非常大,在规模比较大的局点,往往因为一个小的SQL语句不够优化,导致数据库性能急剧下降,小型机idle所剩无几,应用服务器断连、超时,严重影响业务的正常运行。因此,称低效的SQL语句为客服业务的 ......