Reputation: 111
Can anyone elaborate the difference between partition_number and partition_id in sys.partitions (Transact-SQL) , SQL server? Why do we need two different IDs if one could have worked?
Upvotes: 1
Views: 1749
Reputation: 95827
From the documentation you link with added emphasis
partition_id: Indicates the partition ID. Is unique within a database.
partition_number: Is a 1-based partition number within the owning index or heap. For non-partitioned tables and indexes, the value of this column is 1.
partition_id
is the id of the partition within the database. The partition_number
is for the object it is on, as a table can have multiple partitions, and a database can have multiple partitioned tables.
Upvotes: 2
Reputation: 18769
partition_id is unique to the database, similar to a PK for a table. partition_number is the value within a partitioned table or index, since tables (if partitioned) would have more than 1 partition
If you look at this article, you'll see an example of how the dates in the table have different partition_numbers.
To see the partition_id in use, see this article, which shows a query against a partitioned table / index within a database.
from the following queries, also taken from the article:
SELECT *
FROM sys.partitions
WHERE object_id = OBJECT_ID('dbo.HeapTest');
SELECT *
FROM sys.partitions
WHERE object_id = OBJECT_ID('dbo.ClusteredIndexTest');
Upvotes: 1