Solved

How does SQL Server 2005 know which partition to use?

Posted on 2007-03-27
8
176 Views
Last Modified: 2010-03-19
Most examples for SQL Server 2005 involve a sales table that you split based on date, i.e. sales records prior to 2000 go to this partition, and the ones after that go to another one. Nice and simple.

Say I have a sales table:

id    Amount    Date
1    10            1/1/1999
2    9.99         1/1/2007

Now then, I put all the records prior to 2000 in it's own partition.

So when I do something like this: SELECT * FROM Sales WHERE DATE = 1/1/1999
the SQL server will know which partition to look at. Very nice.

Now then, if I do this: SELECT * FROM Sales WHERE id = 1
How will the SQL server know which partition to look at?


Thank You!
0
Comment
Question by:krupini
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 18800619
it knows because the "date"  column has been defined as the partitioning key  with a set of "constraint" ranges
so tableA is the only 1 which could contain pre 2000 data...

if you don't specify the partition key in your query each partition/table/view will be searched for rows matching your criteria... it only if a specific partition key criteria is available that only the matching object will be searched...

hth
0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 18800627
remeber your partitioning key doesn't have to be unique within the table... and you'll still need a primary key
which is unique for performance / validity reasons.  
0
 
LVL 8

Accepted Solution

by:
drydenhogg earned 500 total points
ID: 18800652
Low fat is correct, it will index seek / scan (index dependant) each of the partitions within a partitioned table. It should run each partition seek / scan in parrallel (assuming your not limiting the DOP).

0
 

Author Comment

by:krupini
ID: 18800761
So from what I understand, if the date is not specified, which is a partition key, the SQL server will look in all partitions, one by one.

Is there any specific order which the SQL server will use to look at partitions? For example, will it look at the most recent partition first (the one for 2000 - Now) records, and if it's not there it will look at (<2000) partition?

Thanks.
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 8

Expert Comment

by:drydenhogg
ID: 18800798
It will look in all partitions in parallel, 1 thread per partition. (Unless DOP prevents the parallelism)
0
 
LVL 5

Expert Comment

by:Atropa
ID: 18801551
Oh no fair, the cookie should so go to lowfat - concidering it is a diet cookie that is
0
 

Author Comment

by:krupini
ID: 18803332
drydenhogg explanation was more clear and to the point. I should have split the points, I wish I could edit the decision ....
0
 
LVL 5

Expert Comment

by:Atropa
ID: 18803354
Eh, he would have needed a low fat one anyway and where is the joy in sugar-free cookies!
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Suggested Solutions

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This video discusses moving either the default database or any database to a new volume.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now