-- 创建表
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. LeetCode28 Implement strStr()

    题目: Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if ne ...

  2. java 输入输出 io

    学习JAVA  输入输出篇 java不像C中拥有scanf这样功能强大的函数,大多是通过定义输入输出流对象.常用的类有BufferedReader,Scanner.实例程序:一,利用 Scanner ...

  3. jquery plugins —— datatables 增加行号

    table = $("#Table").DataTable({ "rowCallback": function (row, data, dataIndex) { ...

  4. Spring学习总结二——SpringIOC容器二

    一:指定bean的依赖关系 例如examplebean对象依赖examplebean1对象,那么在创建examplebean对象之前就 需要先创建examplebean1对象. 1:创建Example ...

  5. Delphi数组复制

    const AA : arrary[0..4] of byte =(0,1,2,3,4) var BB : arrary[0..4] of byte; begin BB := AA ;   {这样是错 ...

  6. HDU 1233 还是畅通工程 (最小生成树)

    还是畅通工程 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  7. js实现遮罩以及弹出可移动登录窗口

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. Ubuntu 15.04 配置VPN的方法详解

    源 起 不久前因为要更新AndroidSDK 和查找相关资料, 但有些方式不能墙了, 所以为了节约时间成本, 购买了为期一个月的VPN,  对方发来邮件, 提供了二十几个服务器地址, 以及一套自动生成 ...

  9. jQuery中的选择器<思维导图>

    选择器是jQuery的重要组成部分,在jQuery中,对事件处理.遍历DOM和Ajax操作都依赖于选择器.如果能熟练地使用选择器,不仅能简化代码,而且可以达到事半功倍的效果. 下面是关于jQuery中 ...

  10. Zend studio 12.5.1破解过程

    开始学习php了 今天又安装了一下Zend  之前找了很久的教程终于成了 , 今天换了一台电脑需要重新安装一下 又点忘记了. 就讲这个过程写下来 1.安装zend studio 12.5.1.这个过程 ...