SQL语句优化
对同一张表进行两种方式查询(结果集相同):
case1 查询条件:包括计算机名,昵称,添加时间等等一些限制条件字段。而且需联表查询别的表
查询数据量: 100万 200万
单纯执行SQL语句所需时间:31毫秒 31毫秒
循环遍历数据集所需时间: 57秒 1分50秒
case 2查询条件:无
select * from 【表】
查询数据量: 100万 200万
单纯执行SQL语句所需时间:31毫秒 31毫秒
循环遍历数据集所需时间: 20秒 40秒
注意下循环遍历数据集时间(纵向100万的,或者200万的都行),查询条件不一样,尽管最终查询数据量是一样的,但是遍历时间差别很大。
为什么呢?
可不可以这么理解,SQL语句越复杂(或者说优化程度没那么高),影响的不是SQL本身的执行,而是数据的提取呢?
相关文档:
固定长度(char)与可变长度(varchar)字符数据类型
char[(n)]
长度为n个字节的固定长度且非Unicode的字符数据。n必须是一个介于1和8,000之间的数值。存储大小为n个字节。char在SQL-92中的同义词为character。
varchar[(n)]
长度为n个字节的可变长度且非Unicode的字符数据。n必须是一个介于1和8,000之间的数值。存储大小为 ......
Sql Server中的日期与时间函数
1. 当前系统日期、时间
select getdate()
2. dateadd 在向指定日期加上一段时间的基础上,返回新的 datetime 值
例如:向日期加上2天
select dateadd(day,2,'2004-10-15') --返回:2004-10-17 00:00:00.000
......
使用SQL Server导入/导出Excel,包含部分错误信息处理方法;
操作手记,留此备查
/*
导入
*/
--错误信息如下时:
--Msg 15281, Level 16, State 1, Line 2
--SQL Server blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'Ad Hoc Distributed Queries' because this component is turned off as ......
ch02
--3-4
select * from orders
where 'México D.F.' in
(select City
from Customers
where Orders.CustomerID = Customers.CustomerID )
--3-5
select * from orders
where 'usa' =
(select Country
from Customers
where Orders.CustomerID = Customers.CustomerID )
--4-1
select * from or ......
use Dbname
go
select
[表名]=c.Name,
[表说明]=isnull(f.[value],''),
[列名]=a.Name,
[列序號]=a.Column_id,
&nbs ......