Finding a Date in a Partitioned Table in SQL Server

When running queries on a partitioned table in SQL Server, do I need to do something special?

The reason I am asking is because we have a fairly large SQL Server table that is split into `datetime2 (2) 'columns by day.

Each day is mapped to its own filegroup, with a file in that filegroup named appropriately, eg Logs_2014-09-15.ndf

.

If I make a query on this table that says it only covers 2 days. I can see that in ResourceMonitor SQL Server is accessing more than 2 daily files .ndf

. (edit, in fact I noticed that it goes and looks through each one, even if I select a day that falls into section1)

In my understanding with partitioned tables, it should only search among the relevant data / partitions it needs?

So my questions are:

  • This is true?
  • does how I compare the effect of a column DateTime2

    with a query?

    For example, I could query like this:

    select * from LogsTable
    where [date] like '2014-09-15'
    
          

    or I could do:

    select * from LogsTable
    where [date] = CAST('2014-09-15'AS DATETIME2)
    
          

  • Whatever the section function automatically looks at the element [time]

    if it is in the query and then sends sql to the correct section?

+3


source to share


1 answer


Have you tried with this:

      



select * from LogsTable where Dateadd (D, 0, Datediff (D, 0, [date])) = CAST ('2014-09-15'AS DATETIME2)

+1


source







All Articles