sql server 中 bigint 和 datetime 性能比较
-- 创建表
create table Test_tbl
(
ID varchar(40) primary key nonclustered,
IntCol int,
DateCol datetime
) --==================================================================================
-- 【100w数据测试】
--==================================================================================
-- 创建100w测试数据
declare @j int
declare @data float
declare @style bigint
set @j = 1
while @j<1000000
begin
set @style = cast(replace(replace(replace(convert(varchar(30),GETDATE(),120),'-',''),':',''), ' ', '') as bigint)
insert into Test_tbl(ID, IntCol, DateCol) values(NEWID(),@style, getdate())
set @j = @j + 1
end declare @d datetime
set @d = getdate()
declare @i int print '【100w数据 查询100次测试】'
-- 测试性能1,datetime
-------------------------------------------------------------------------------------
set nocount on -- 不显示受影响行数
set @i=0
while @i <20
begin
select top 1 * from Test_tbl where DateCol>getdate()
set @i = @i+1
end
-------------------------------------------------------------------------------------
select [语句执行时间(毫秒)]=datediff(ms, @d, getdate())
set nocount off
print '100w数据 date 语句执行时间(毫秒):' + CONVERT(varchar(30), datediff(ms, @d, getdate())) -- 测试性能2,int
-------------------------------------------------------------------------------------
set nocount on -- 不显示受影响行数
set @i=0
while @i <20
begin
select top 1 * from Test_tbl where IntCol>20151212030303
set @i = @i+1
end
-------------------------------------------------------------------------------------
select [语句执行时间(毫秒)]=datediff(ms, @d, getdate())
set nocount off
print '100w数据 int 语句执行时间(毫秒):' + CONVERT(varchar(30), datediff(ms, @d, getdate())) --==================================================================================
-- 【1000w数据测试】
--==================================================================================
-- 创建900w测试数据,累计1000w
set @j = 1
while @j<9000000
begin
set @style = cast(replace(replace(replace(convert(varchar(30),GETDATE(),120),'-',''),':',''), ' ', '') as bigint)
insert into Test_tbl(ID, IntCol, DateCol) values(NEWID(),@style,getdate())
set @j = @j + 1
end print '【1000w数据 查询100次测试】'
-- 测试性能1,datetime
-------------------------------------------------------------------------------------
set nocount on -- 不显示受影响行数
set @i=0
while @i <100
begin
select top 1 * from Test_tbl where DateCol>getdate()
set @i = @i+1
end
-------------------------------------------------------------------------------------
select [语句执行时间(毫秒)]=datediff(ms, @d, getdate())
set nocount off
print '1000w数据 date 语句执行时间(毫秒):' + CONVERT(varchar(30), datediff(ms, @d, getdate())) -- 测试性能2,int
-------------------------------------------------------------------------------------
set nocount on -- 不显示受影响行数
set @i=0
while @i <100
begin
select top 1 * from Test_tbl where IntCol>20151212030303
set @i = @i+1
end
-------------------------------------------------------------------------------------
select [语句执行时间(毫秒)]=datediff(ms, @d, getdate())
set nocount off
print '1000w数据 int 语句执行时间(毫秒):' + CONVERT(varchar(30), datediff(ms, @d, getdate()))
sql server 中 bigint 和 datetime 性能比较的更多相关文章
- SQL Server中datetimeset转换datetime类型问题浅析
在SQL Server中,数据类型datetimeoffset转换为datetime类型或datetime2类型时需要特别注意,有可能一不小心你可能会碰到下面这种情况.下面我们构造一个简单案例,模拟一 ...
- SQL Server中使用Check约束提升性能
在SQL Server中,SQL语句的执行是依赖查询优化器生成的执行计划,而执行计划的好坏直接关乎执行性能. 在查询优化器生成执行计划过程中,需要参考元数据来尽可能生成高效的执行计划, ...
- SQL Server中提前找到隐式转换提升性能的办法
http://www.cnblogs.com/shanksgao/p/4254942.html 高兄这篇文章很好的谈论了由于数据隐式转换造成执行计划不准确,从而造成了死锁.那如果在事情出现之前 ...
- SQL SERVER中用户定义标量函数(scalar user defined function)的性能问题
用户定义函数(UDF)分类 SQL SERVER中的用户定义函数(User Defined Functions 简称UDF)分为标量函数(Scalar-Valued Function)和表值函数(T ...
- 为什么SQL语句Where 1=1 and在SQL Server中不影响性能
最近一个朋友和我探讨关于Where 1=1 and这种形式的语句会不会影响性能.最后结论是不影响. 虽然结论正确,但对问题的认识却远远没有解决问题的根本.实际上在T-SQL语句的书写过 ...
- SQL Server中一个隐性的IO性能杀手-Forwarded record
简介 最近在一个客户那里注意到一个计数器很高(Forwarded Records/Sec),伴随着间歇性的磁盘等待队列的波动.本篇文章分享什么是forwarded record,并从原理上谈一 ...
- SQL Server中多表连接时驱动顺序对性能的影响
本文出处:http://www.cnblogs.com/wy123/p/7106861.html (保留出处并非什么原创作品权利,本人拙作还远远达不到,仅仅是为了链接到原文,因为后续对可能存在的一些错 ...
- Java中的Date Time 与SQL Server 2005里的Datetime 之间的交互
Preface Environment:Platform: Windows XPLanguage: Java 1.5IDE: MyEclipse 6.0.1Database: SQL Server 2 ...
- SQL SERVER 中的smalldatetime和datetime区别
原文:SQL SERVER 中的smalldatetime和datetime区别 smalldatetime不能到秒. 不過它占的空間小.(4位) datetime(8位) 而且兩者的時間範圍不一樣. ...
随机推荐
- C. Mobile phones
Suppose that the fourth generation mobile phone base stations in the Tampere area operate as follows ...
- 属性通知之INotifyPropertyChanged
为什么后台绑定的值改变了前台不发生变化了? 针对这个初学者很容易弄错的问题,这里介绍一下INotifyPropertyChanged的用法 INotifyPropertyChanged:用于绑定属性更 ...
- 使用Calendar 将当月日历打印出来
package com.date; import java.text.DateFormatSymbols; import java.util.Calendar; import org.junit.Te ...
- 免费公测:RDS只读实例
免费公测:RDS只读实例 简要介绍 在对数据库有少量写请求,但有大量的读请求的应用场景下,单个实例可能无法抵抗读取压力, 甚至对主流程业务产生影响.为了实现读取能力的弹性扩展,分担数据库压力,阿里 ...
- codeforces 680A A. Bear and Five Cards(水题)
题目链接: A. Bear and Five Cards //#include <bits/stdc++.h> #include <vector> #include <i ...
- 使用tornado的gen.coroutine进行异步编程
在tornado3发布之后,强化了coroutine的概念,在异步编程中,替代了原来的gen.engine, 变成现在的gen.coroutine.这个装饰器本来就是为了简化在tornado中的异步编 ...
- hdu 3111 DLX解数独
思路:裸的DLX解数独.关键是建图,感觉还不如写个dfs直接,DLX写这个的代码很烦. #include<set> #include<map> #include<cmat ...
- [转]如何制作tizen镜像文件(图文教程)?
http://blog.csdn.net/flydream0/article/details/9163119 之前已讲解了如何下载及编译tizen源码(http://blog.csdn.net/fly ...
- 重磅消息:JavaFX官方文档翻译完毕
经过XMan团队业余时间半年的努力,终于将JavaFX官方文档全部翻译完毕,内容已经全部在http://www.javafxchina.net中发表. 中文文档具体目录如下: 第一篇 开始学习Java ...
- 在IIS上发布项目后浏览时报的错:Unable to make the session state request to the session state server
错误描述: Unable to make the session state request to the session state server. Please ensure that the A ...