-- 创建表
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. solr中通过SFTP访问文件建立索引

    需求: 从oracle数据库中根据记录的文件名filename_html(多个文件以逗号隔开),文件路径path,备用文件名bakpath中获取 主机172.21.0.31上对应的html文件内容,并 ...

  2. leetcode题解: Remove Duplicates from Sorted List(已排序单链表去重)

    题目: Given a sorted linked list, delete all duplicates such that each element appear only once. For e ...

  3. C++中模板函数或模板类中关键词class和typename

    ##区别 基本上来说,class和typename几乎没有区别.在可以使用class的地方都可以使用typename,在使用typename的地方也几乎可以使用class. 可以看出我加黑了两个子:几 ...

  4. X86汇编语言中的registers相关

    0.写在前面 本文中总结于王爽老师的汇编语言,建议有兴趣的都买一本,以支持王爽老师的辛勤付出.再者,这本书写的确实很nice. 8086CPU共有14个registers:AX, BX, CX, DX ...

  5. My Linux API

    @图形界面与命令行界面切换 Linux预设提供了六个命令窗口终端机让我们来登录.默认我们登录的就是第一个窗口,也就是tty1,这个六个窗口分别为tty1,tty2 … tty6,你可以按下Ctrl + ...

  6. 转: ios app架构设计

    http://keeganlee.me/post/architecture/20160107 看完这一系列文章后就知道怎么回答这类问题了: App架构设计经验谈:接口的设计 App架构设计经验谈:技术 ...

  7. Common工具类的验证码类的使用(未实现验证)

    验证码接收 using System; using System.Collections.Generic; using System.Linq; using System.Web; using CZB ...

  8. 微信小程序开发1

    关于微信小程序的开发.对于我们这些没学过oc或者android的人来说,无疑是一个令人鸡冻的好消息.这段时间研究了微信小程序开发.关于小程序的注册,认证和基础环境的搭建,官方文档已经非常详细了.这里就 ...

  9. IIS Session问题解决

    Windows Server 2008 +IIS +ASP.net +SQLServer2008搭建的内部WEB系统. 发现用户Session总是不知不觉就自行遗失,原因就是 IIS的不稳定性将导致S ...

  10. Part 32 Abstract classes in c#