partition_id 和 partition_number 之间的区别

Difference between partition_id and partition_number

谁能详细说明 sys.partitionspartition_numberpartition_id 之间的区别(交易-SQL) , SQL 服务器?如果一个 ID 可以工作,为什么我们需要两个不同的 ID?

来自 documentation 你 link 加了强调

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 是数据库中分区的id。 partition_number 用于它所在的对象,因为 table 可以有多个分区,而数据库可以有多个分区 table。

partition_id是数据库唯一的,类似于table的PK。 partition_number 是分区 table 或索引中的值,因为 tables(如果分区)将有超过 1 个分区

如果您查看 this article,您会看到 table 中的日期有何不同的示例 partition_numbers .

要查看正在使用的 partition_id,请参阅 this article,它显示了针对数据库中分区 table / 索引的查询。

来自以下查询,也摘自文章:

SELECT *
FROM sys.partitions
WHERE object_id = OBJECT_ID('dbo.HeapTest');

SELECT *
FROM sys.partitions
WHERE object_id = OBJECT_ID('dbo.ClusteredIndexTest');