How to Map Multiple Partitions to a Single Filegroup in SQL Server (T-SQL)

If you’re familiar with creating partitioned tables in SQL Server, you might be used to creating a separate filegroup for each partition. This has its benefits, and may very well be the method you would choose in most scenarios.

However, you also have the option of mapping multiple partitions to a single filegroup.

In this article I share two examples of mapping multiple partitions to a single filegroup.

  • Example 1 maps all partitions to a single filegroup.
  • Example 2 maps some partitions to one filegroup, and some to another.
Continue reading

Find Out Which Partition a Given Value Would be Mapped to in SQL Server (T-SQL)

If you have a partitioned table or index in SQL Server, and you want to determine which partition a given value would be mapped to, you can do this nice and quickly with the $PARTITION system function.

All you need to know is the name of the partition function (and of course, the value you’re interested in).

Continue reading

3 Ways to Return the Number of Rows in Each Partition in SQL Server (T-SQL)

If you’ve previously created a partitioned table in SQL Server, and you now want to know how many rows are being stored in each partition, here are three queries you can use.

In particular, you can:

  • Query the sys.dm_db_partition_stats view
  • Query the sys.partitions view
  • Use the $PARTITION function in a query

Below are examples of all three.

Continue reading