-- 创建表
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 性能比较的更多相关文章

  1. SQL Server中datetimeset转换datetime类型问题浅析

    在SQL Server中,数据类型datetimeoffset转换为datetime类型或datetime2类型时需要特别注意,有可能一不小心你可能会碰到下面这种情况.下面我们构造一个简单案例,模拟一 ...

  2. SQL Server中使用Check约束提升性能

        在SQL Server中,SQL语句的执行是依赖查询优化器生成的执行计划,而执行计划的好坏直接关乎执行性能.     在查询优化器生成执行计划过程中,需要参考元数据来尽可能生成高效的执行计划, ...

  3. SQL Server中提前找到隐式转换提升性能的办法

        http://www.cnblogs.com/shanksgao/p/4254942.html 高兄这篇文章很好的谈论了由于数据隐式转换造成执行计划不准确,从而造成了死锁.那如果在事情出现之前 ...

  4. SQL SERVER中用户定义标量函数(scalar user defined function)的性能问题

    用户定义函数(UDF)分类  SQL SERVER中的用户定义函数(User Defined Functions 简称UDF)分为标量函数(Scalar-Valued Function)和表值函数(T ...

  5. 为什么SQL语句Where 1=1 and在SQL Server中不影响性能

        最近一个朋友和我探讨关于Where 1=1 and这种形式的语句会不会影响性能.最后结论是不影响.     虽然结论正确,但对问题的认识却远远没有解决问题的根本.实际上在T-SQL语句的书写过 ...

  6. SQL Server中一个隐性的IO性能杀手-Forwarded record

    简介     最近在一个客户那里注意到一个计数器很高(Forwarded Records/Sec),伴随着间歇性的磁盘等待队列的波动.本篇文章分享什么是forwarded record,并从原理上谈一 ...

  7. SQL Server中多表连接时驱动顺序对性能的影响

    本文出处:http://www.cnblogs.com/wy123/p/7106861.html (保留出处并非什么原创作品权利,本人拙作还远远达不到,仅仅是为了链接到原文,因为后续对可能存在的一些错 ...

  8. Java中的Date Time 与SQL Server 2005里的Datetime 之间的交互

    Preface Environment:Platform: Windows XPLanguage: Java 1.5IDE: MyEclipse 6.0.1Database: SQL Server 2 ...

  9. SQL SERVER 中的smalldatetime和datetime区别

    原文:SQL SERVER 中的smalldatetime和datetime区别 smalldatetime不能到秒. 不過它占的空間小.(4位) datetime(8位) 而且兩者的時間範圍不一樣. ...

随机推荐

  1. Linux下redis安装与使用

         redis官网地址:http://www.redis.io/      最新版本:2.8.3      在Linux下安装Redis非常简单,具体步骤如下(官网有说明):      1.下载 ...

  2. SpringMvc多文件上传简单实现

    public ResponseItem uploadFile(MultipartHttpServletRequest request,FileItem fileItem,PageData pd) { ...

  3. 查找字符对应Unicode码的十进制数字

    //将字符转换为Unicode码中字符对应十进制数字 int byte0 = 'A' & 0xff;//byte0=65 参考文档:http://baike.baidu.com/view/26 ...

  4. 通过GCD、NSOperationQueue队列、NSThread三种方法来创建多线程

    #import "ViewController.h" @interface ViewController () @property (weak, nonatomic) IBOutl ...

  5. 关于Google Chorme中字体小于12px的问题

    问题:当字体大小设置成小于12px时,Google chrome中字体的大小始终显示为12px. 而其他浏览器则没有这个问题. 这时只需要在要改变字体大小的元素中添加 -webkit-transfor ...

  6. 【阿里云产品公测】以开发者角度看ACE服务『ACE应用构建指南』

    作者:阿里云用户mr_wid ,z)NKt#   @I6A9do   如果感觉该评测对您有所帮助, 欢迎投票给本文: UO<claV   RsfTUb)<   投票标题:  28.[阿里云 ...

  7. linux_iptables 详解

    iptables工具__过滤包—命令(-A.-I.-D.-R.-L等).参数(-p.-s.-d.--sport.--dport.-i.-o等).动作-j (ACCEPT.DROP.REJECT.RED ...

  8. Composer 中国镜像

    1.修改Composer的全局配置文件 config.json 使用sudo composer config -l -g 查看composer全局配置信息,在这些信息中查找 [home] 配置项就是 ...

  9. codeforces 677A A. Vanya and Fence(水题)

    题目链接: A. Vanya and Fence time limit per test 1 second memory limit per test 256 megabytes input stan ...

  10. LPSTR、LPCSTR、LPWSTR、LPCWSTR、LPTSTR、LPCTSTR的来源及意义

    1. Unicode字符集: 它是用两个字节表示一个字符的方法.比如字符'A'在ASCII下面是一个字符,可'A'在UNICODE下面是两个字符,高字符用0填充,而且汉字'程'在ASCII下面是两个字 ...