BigInt and datetime performance comparisons in SQL Server

Source: Internet
Author: User
Tags getdate

--Create TABLE TEST_TBL (ID varchar (primary) key nonclustered, Intcol int,datecol datetime)--=============== ===================================================================--"100w Data Test"--============================== ====================================================--Create 100w test data declare @j intdeclare @data floatdeclare @style Bigintset @j = 1while @j<1000000 begin set @style = CAST (replace (replace (varchar (), GETDATE () , (+), '-', '), ': ', '), ', ') as bigint) insert into Test_tbl (ID, Intcol, Datecol) VALUES (NEWID (), @style, GETDATE ( )) Set @j = @j + 1end Declare @d datetimeset @d = GETDATE () Declare @i intprint ' "100w Data Query 100 Tests" '--Test performance 1,datetime   -------------------------------------------------------------------------------------SET NOCOUNT ON--does not show the number of rows affected set @i=0while @i <20begin Select top 1 * from TEST_TBL where Datecol>getdate () set @i = @i+1end----------- --------------------------------------------------------------------------SELECT [Statement Execution time (ms)]=datediff (MS, @d, GETDATE ()) Set NOCOUNT off print ' 100w Data date statement execution time (MS): ' + CONVERT (varchar (+), DateDiff (MS, @d, GETDATE ()))--Test performance 2, int-------------------------------------------------------------------------------------SET NOCOUNT ON--   The number of rows affected is not displayed set @i=0while @i <20begin select top 1 * from TEST_TBL where intcol>20151212030303 set @i = @i+1end-------------------------------------------------------------------------------------SELECT [Statement execution time (milliseconds)] =datediff (MS, @d, GETDATE ()) Set NOCOUNT off print ' 100w data int statement Execution time (ms): ' + CONVERT (varchar), DateDiff (MS, @d, GETDATE ()))--==================================================================================--"1000w Data Test"--======== ==========================================================================--Create 900w test data, cumulative 1000wset @j = 1while @j  <9000000 begin Set @style = CAST (replace (replace (varchar (+), GETDATE (), 120), '-', '), ': ', '), ' ', ') asbigint) insert into Test_tbl (ID, Intcol, Datecol) VALUES (NEWID (), @style, GETDATE ()) Set @j = @j + 1end print ' "100 0w data Query 100 Tests "'--test performance 1, DateTime-------------------------------------------------------------------------------------SET NOCOUNT ON-- The number of rows affected is not displayed set @i=0while @i <100begin select top 1 * from TEST_TBL where Datecol>getdate () set @i = @i+ 1end-------------------------------------------------------------------------------------SELECT [Statement Execution time (MS)]= DateDiff (MS, @d, GETDATE ()) Set NOCOUNT off print ' 1000w data date statement execution time (ms): ' + CONVERT (varchar), DateDiff (MS, @d, Getdat E ()))--Test performance 2,int-------------------------------------------------------------------------------------set    Nocount ON--not showing the number of rows affected set @i=0while @i <100begin select top 1 * from TEST_TBL where intcol>20151212030303 Set @i = @i+1end-------------------------------------------------------------------------------------SELECT [ Statement execution time (ms)]=datediff (MS, @d, GETDATE ()) Set NocoUnt off print ' 1000w data int statement Execution time (ms): ' + CONVERT (varchar (+), DateDiff (MS, @d, GETDATE ())) 

BigInt and datetime performance comparisons in SQL Server

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.