%3CLINGO-SUB%20id%3D%22lingo-sub-369165%22%20slang%3D%22en-US%22%3ELesson%20Learned%20%2360%3A%20Using%20Partition%20Option%20in%20Azure%20SQL%20Managed%20Instance%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-369165%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3EFirst%20published%20on%20MSDN%20on%20Jan%2019%2C%202019%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%20Hello%2C%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Time%20ago%2C%20we%20discussed%20in%20this%20%3CA%20href%3D%22https%3A%2F%2Fblogs.msdn.microsoft.com%2Fazuresqldbsupport%2F2018%2F05%2F07%2Flesson-learned-43-using-partitioning-option-for-azure-sql-database%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3E%20post%20%3C%2FA%3E%20about%20partitioning%20option%20in%20Azure%20SQL%20Database.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20One%20of%20the%20main%20differences%20creating%20this%20partition%20in%20Azure%20SQL%20Database%20is%20all%20partition%20will%20use%20the%20same%20filegroup.%20In%20Azure%20SQL%20Managed%20Instance%20we%20could%20create%20different%20filegroups%20and%26nbsp%3Bfiles%20for%20each%20partition%20having%20a%20better%20performance%20having%20multiple%20files%20per%20database.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Let%20me%20show%20you%20an%20example%3A%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%5Bcode%20language%3D%22SQL%22%5D%20%3CBR%20%2F%3E%20CREATE%20DATABASE%20dbPartitionP15%20%3CBR%20%2F%3E%20go%20%3CBR%20%2F%3E%20USE%20dbPartitionP15%20%3CBR%20%2F%3E%20GO%20%3CBR%20%2F%3E%20--%20%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%20%3CBR%20%2F%3E%20--%20How%20many%20filegroups%2Ffiles%20that%20we%20have%20in%20this%20database%20%3CBR%20%2F%3E%20--%20%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%20%3CBR%20%2F%3E%20SELECT%20*%20FROM%20SYS.sysFILES%20%3CBR%20%2F%3E%20--%20%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%20%3CBR%20%2F%3E%20--%20Create%20the%20filegroups%20%3CBR%20%2F%3E%20--%20%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%20%3CBR%20%2F%3E%20ALTER%20DATABASE%20dbPartitionP15%20%3CBR%20%2F%3E%20ADD%20FILEGROUP%20Data01%3B%20%3CBR%20%2F%3E%20GO%20%3CBR%20%2F%3E%20ALTER%20DATABASE%20dbPartitionP15%20%3CBR%20%2F%3E%20ADD%20FILEGROUP%20Data02%3B%20%3CBR%20%2F%3E%20GO%20%3CBR%20%2F%3E%20ALTER%20DATABASE%20dbPartitionP15%20%3CBR%20%2F%3E%20ADD%20FILEGROUP%20Data03%3B%20%3CBR%20%2F%3E%20GO%20%3CBR%20%2F%3E%20ALTER%20DATABASE%20dbPartitionP15%20%3CBR%20%2F%3E%20ADD%20FILEGROUP%20Data04%3B%20%3CBR%20%2F%3E%20GO%20%3CBR%20%2F%3E%20ALTER%20DATABASE%20dbPartitionP15%20%3CBR%20%2F%3E%20ADD%20FILEGROUP%20Data05%3B%20%3CBR%20%2F%3E%20GO%20%3CBR%20%2F%3E%20ALTER%20DATABASE%20dbPartitionP15%20%3CBR%20%2F%3E%20ADD%20FILEGROUP%20Data06%3B%20%3CBR%20%2F%3E%20GO%20%3CBR%20%2F%3E%20ALTER%20DATABASE%20dbPartitionP15%20%3CBR%20%2F%3E%20ADD%20FILEGROUP%20Data07%3B%20%3CBR%20%2F%3E%20GO%20%3CBR%20%2F%3E%20ALTER%20DATABASE%20dbPartitionP15%20%3CBR%20%2F%3E%20ADD%20FILEGROUP%20Data08%3B%20%3CBR%20%2F%3E%20GO%20%3CBR%20%2F%3E%20ALTER%20DATABASE%20dbPartitionP15%20%3CBR%20%2F%3E%20ADD%20FILEGROUP%20Data09%3B%20%3CBR%20%2F%3E%20GO%20%3CBR%20%2F%3E%20ALTER%20DATABASE%20dbPartitionP15%20%3CBR%20%2F%3E%20ADD%20FILEGROUP%20Data10%3B%20%3CBR%20%2F%3E%20GO%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20--%20%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%20%3CBR%20%2F%3E%20--%20Define%20a%20file%20per%20filegroup%20as%20an%20example%20%3CBR%20%2F%3E%20--%20%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20ALTER%20DATABASE%20dbPartitionP15%20%3CBR%20%2F%3E%20ADD%20FILE%20%3CBR%20%2F%3E%20(%20%3CBR%20%2F%3E%20NAME%20%3D%20Data01_01%2C%20%3CBR%20%2F%3E%20SIZE%20%3D%2050MB%2C%20%3CBR%20%2F%3E%20MAXSIZE%20%3D%2050MB%2C%20%3CBR%20%2F%3E%20FILEGROWTH%20%3D%2010MB%20%3CBR%20%2F%3E%20)%20%3CBR%20%2F%3E%20TO%20FILEGROUP%20Data01%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20ALTER%20DATABASE%20dbPartitionP15%20%3CBR%20%2F%3E%20ADD%20FILE%20%3CBR%20%2F%3E%20(%20%3CBR%20%2F%3E%20NAME%20%3D%20Data02_01%2C%20%3CBR%20%2F%3E%20SIZE%20%3D%2050MB%2C%20%3CBR%20%2F%3E%20MAXSIZE%20%3D%2050MB%2C%20%3CBR%20%2F%3E%20FILEGROWTH%20%3D%2010MB%20%3CBR%20%2F%3E%20)%20%3CBR%20%2F%3E%20TO%20FILEGROUP%20Data02%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20ALTER%20DATABASE%20dbPartitionP15%20%3CBR%20%2F%3E%20ADD%20FILE%20%3CBR%20%2F%3E%20(%20%3CBR%20%2F%3E%20NAME%20%3D%20Data03_01%2C%20%3CBR%20%2F%3E%20SIZE%20%3D%2050MB%2C%20%3CBR%20%2F%3E%20MAXSIZE%20%3D%2050MB%2C%20%3CBR%20%2F%3E%20FILEGROWTH%20%3D%2010MB%20%3CBR%20%2F%3E%20)%20%3CBR%20%2F%3E%20TO%20FILEGROUP%20Data03%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20ALTER%20DATABASE%20dbPartitionP15%20%3CBR%20%2F%3E%20ADD%20FILE%20%3CBR%20%2F%3E%20(%20%3CBR%20%2F%3E%20NAME%20%3D%20Data04_01%2C%20%3CBR%20%2F%3E%20SIZE%20%3D%2050MB%2C%20%3CBR%20%2F%3E%20MAXSIZE%20%3D%2050MB%2C%20%3CBR%20%2F%3E%20FILEGROWTH%20%3D%2010MB%20%3CBR%20%2F%3E%20)%20%3CBR%20%2F%3E%20TO%20FILEGROUP%20Data04%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20ALTER%20DATABASE%20dbPartitionP15%20%3CBR%20%2F%3E%20ADD%20FILE%20%3CBR%20%2F%3E%20(%20%3CBR%20%2F%3E%20NAME%20%3D%20Data05_01%2C%20%3CBR%20%2F%3E%20SIZE%20%3D%2050MB%2C%20%3CBR%20%2F%3E%20MAXSIZE%20%3D%2050MB%2C%20%3CBR%20%2F%3E%20FILEGROWTH%20%3D%2010MB%20%3CBR%20%2F%3E%20)%20%3CBR%20%2F%3E%20TO%20FILEGROUP%20Data05%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20ALTER%20DATABASE%20dbPartitionP15%20%3CBR%20%2F%3E%20ADD%20FILE%20%3CBR%20%2F%3E%20(%20%3CBR%20%2F%3E%20NAME%20%3D%20Data06_01%2C%20%3CBR%20%2F%3E%20SIZE%20%3D%2050MB%2C%20%3CBR%20%2F%3E%20MAXSIZE%20%3D%2050MB%2C%20%3CBR%20%2F%3E%20FILEGROWTH%20%3D%2010MB%20%3CBR%20%2F%3E%20)%20%3CBR%20%2F%3E%20TO%20FILEGROUP%20Data06%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20ALTER%20DATABASE%20dbPartitionP15%20%3CBR%20%2F%3E%20ADD%20FILE%20%3CBR%20%2F%3E%20(%20%3CBR%20%2F%3E%20NAME%20%3D%20Data07_01%2C%20%3CBR%20%2F%3E%20SIZE%20%3D%2050MB%2C%20%3CBR%20%2F%3E%20MAXSIZE%20%3D%2050MB%2C%20%3CBR%20%2F%3E%20FILEGROWTH%20%3D%2010MB%20%3CBR%20%2F%3E%20)%20%3CBR%20%2F%3E%20TO%20FILEGROUP%20Data07%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20ALTER%20DATABASE%20dbPartitionP15%20%3CBR%20%2F%3E%20ADD%20FILE%20%3CBR%20%2F%3E%20(%20%3CBR%20%2F%3E%20NAME%20%3D%20Data08_01%2C%20%3CBR%20%2F%3E%20SIZE%20%3D%2050MB%2C%20%3CBR%20%2F%3E%20MAXSIZE%20%3D%2050MB%2C%20%3CBR%20%2F%3E%20FILEGROWTH%20%3D%2010MB%20%3CBR%20%2F%3E%20)%20%3CBR%20%2F%3E%20TO%20FILEGROUP%20Data08%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20ALTER%20DATABASE%20dbPartitionP15%20%3CBR%20%2F%3E%20ADD%20FILE%20%3CBR%20%2F%3E%20(%20%3CBR%20%2F%3E%20NAME%20%3D%20Data09_01%2C%20%3CBR%20%2F%3E%20SIZE%20%3D%2050MB%2C%20%3CBR%20%2F%3E%20MAXSIZE%20%3D%2050MB%2C%20%3CBR%20%2F%3E%20FILEGROWTH%20%3D%2010MB%20%3CBR%20%2F%3E%20)%20%3CBR%20%2F%3E%20TO%20FILEGROUP%20Data09%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20ALTER%20DATABASE%20dbPartitionP15%20%3CBR%20%2F%3E%20ADD%20FILE%20%3CBR%20%2F%3E%20(%20%3CBR%20%2F%3E%20NAME%20%3D%20Data10_01%2C%20%3CBR%20%2F%3E%20SIZE%20%3D%2050MB%2C%20%3CBR%20%2F%3E%20MAXSIZE%20%3D%2050MB%2C%20%3CBR%20%2F%3E%20FILEGROWTH%20%3D%2010MB%20%3CBR%20%2F%3E%20)%20%3CBR%20%2F%3E%20TO%20FILEGROUP%20Data10%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20--%20%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%20%3CBR%20%2F%3E%20--%20Create%20the%20partition%20function.%20%3CBR%20%2F%3E%20--%20%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%20%3CBR%20%2F%3E%20CREATE%20PARTITION%20FUNCTION%20PF_HASH_BY_VALUE%20(INT)%20AS%20RANGE%20LEFT%20%3CBR%20%2F%3E%20FOR%20VALUES%20(100000%2C%20200000%2C%20300000%2C%20400000%2C%20500000%2C%20600000%2C%20700000%2C%20800000%2C%20900000)%20%3CBR%20%2F%3E%20SELECT%20*%20FROM%20sys.partition_functions%20%3CBR%20%2F%3E%20--%20%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%20%3CBR%20%2F%3E%20--%20Create%20the%20schema%20partition.%20%3CBR%20%2F%3E%20--%20%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%20%3CBR%20%2F%3E%20CREATE%20PARTITION%20SCHEME%20PS_HASH_BY_VALUE%20%3CBR%20%2F%3E%20AS%20PARTITION%20PF_HASH_BY_VALUE%20%3CBR%20%2F%3E%20TO%20(Data01%2CData02%2CData03%2CData04%2CData05%2CData06%2CData07%2CData08%2CData09%2CData10)%3B%20%3CBR%20%2F%3E%20GO%20%3CBR%20%2F%3E%20SELECT%20*%20FROM%20sys.partition_schemes%20%3CBR%20%2F%3E%20--%20%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%20%3CBR%20%2F%3E%20--%20Configure%20the%20Distribution%20data.%20%3CBR%20%2F%3E%20--%20%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%20%3CBR%20%2F%3E%20SELECT%20%3CBR%20%2F%3E%20MY_VALUE%2C%20%3CBR%20%2F%3E%20%24PARTITION.PF_HASH_BY_VALUE(MY_VALUE)%20AS%20HASH_IDX%20%3CBR%20%2F%3E%20FROM%20%3CBR%20%2F%3E%20(%20%3CBR%20%2F%3E%20VALUES%20%3CBR%20%2F%3E%20(1)%2C%20%3CBR%20%2F%3E%20(100001)%2C%20%3CBR%20%2F%3E%20(200001)%2C%20%3CBR%20%2F%3E%20(300001)%2C%20%3CBR%20%2F%3E%20(400001)%2C%20%3CBR%20%2F%3E%20(500001)%2C%20%3CBR%20%2F%3E%20(600001)%2C%20%3CBR%20%2F%3E%20(700001)%2C%20%3CBR%20%2F%3E%20(800001)%2C%20%3CBR%20%2F%3E%20(900001)%20%3CBR%20%2F%3E%20)%20AS%20TEST%20(MY_VALUE)%3B%20%3CBR%20%2F%3E%20GO%20%3CBR%20%2F%3E%20--%20%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%20%3CBR%20%2F%3E%20--%20Create%20the%20table.%20%3CBR%20%2F%3E%20--%20%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%20%3CBR%20%2F%3E%20CREATE%20TABLE%20%5BTBL_PARTITION%5D%20%3CBR%20%2F%3E%20(%20%5BMY_VALUE%5D%20%5Bint%5D%20NOT%20NULL%2C%20Age%20float%20%2C%20%3CBR%20%2F%3E%20CONSTRAINT%20%5BPK_TBL_PARTITION%5D%20PRIMARY%20KEY%20CLUSTERED%20(%5BMY_VALUE%5D%20ASC)%20%3CBR%20%2F%3E%20)%20ON%20PS_HASH_BY_VALUE%20(%5BMY_VALUE%5D)%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20--%20%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%20%3CBR%20%2F%3E%20--%20Add%20some%20rows%20%3CBR%20%2F%3E%20--%20%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20DECLARE%20%40nValues%20AS%20INTEGER%20%3D%200%20%3CBR%20%2F%3E%20DECLARE%20%40nFormat%20AS%20INTEGER%20%3D%200%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20begin%20transaction%20%3CBR%20%2F%3E%20WHILE%20%40nFormat%20%26lt%3B10%20%3CBR%20%2F%3E%20BEGIN%20%3CBR%20%2F%3E%20SET%20%40nFormat%20%3D%20%40nFormat%20%2B1%20%3CBR%20%2F%3E%20SET%20%40nValues%20%3D%200%20%3CBR%20%2F%3E%20WHILE%20%40nValues%26lt%3B%3D90000%20%3CBR%20%2F%3E%20BEGIN%20%3CBR%20%2F%3E%20SET%20%40nValues%20%3D%40nValues%2B1%20%3CBR%20%2F%3E%20insert%20into%20%5BTBL_PARTITION%5D%20(my_value%2CAge)%20values(CONVERT(int%2CCONVERT(varchar(20)%2C%40nformat)%2BCONVERT(varchar(20)%2C%40nValues))%2CRAND())%20%3CBR%20%2F%3E%20END%20%3CBR%20%2F%3E%20END%20%3CBR%20%2F%3E%20commit%20transaction%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20--%20%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%20%3CBR%20%2F%3E%20--%20Review%20the%20partition%20distribution.%20%3CBR%20%2F%3E%20--%20%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%20%3CBR%20%2F%3E%20SELECT%20object_name(object_id)%2C*%20FROM%20sys.dm_db_partition_stats%20where%20object_name(object_id)%3D'TBL_PARTITION'%20%3CBR%20%2F%3E%20%5B%2Fcode%5D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Enjoy!%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-369165%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20MSDN%20on%20Jan%2019%2C%202019%20Hello%2CTime%20ago%2C%20we%20discussed%20in%20this%20post%20about%20partitioning%20option%20in%20Azure%20SQL%20Database.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-369165%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Eadd%20file%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Eazure%20sql%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Efilegroup%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Emanaged%20instance%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Epartition%20function%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Epartition%20scheme%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Esys%20dm_db_partition_stats%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
First published on MSDN on Jan 19, 2019
Hello,

Time ago, we discussed in this post about partitioning option in Azure SQL Database.

One of the main differences creating this partition in Azure SQL Database is all partition will use the same filegroup. In Azure SQL Managed Instance we could create different filegroups and files for each partition having a better performance having multiple files per database.

Let me show you an example:

[code language="SQL"]
CREATE DATABASE dbPartitionP15
go
USE dbPartitionP15
GO
-- ====================================
-- How many filegroups/files that we have in this database
-- ====================================
SELECT * FROM SYS.sysFILES
-- ====================================
-- Create the filegroups
-- ====================================
ALTER DATABASE dbPartitionP15
ADD FILEGROUP Data01;
GO
ALTER DATABASE dbPartitionP15
ADD FILEGROUP Data02;
GO
ALTER DATABASE dbPartitionP15
ADD FILEGROUP Data03;
GO
ALTER DATABASE dbPartitionP15
ADD FILEGROUP Data04;
GO
ALTER DATABASE dbPartitionP15
ADD FILEGROUP Data05;
GO
ALTER DATABASE dbPartitionP15
ADD FILEGROUP Data06;
GO
ALTER DATABASE dbPartitionP15
ADD FILEGROUP Data07;
GO
ALTER DATABASE dbPartitionP15
ADD FILEGROUP Data08;
GO
ALTER DATABASE dbPartitionP15
ADD FILEGROUP Data09;
GO
ALTER DATABASE dbPartitionP15
ADD FILEGROUP Data10;
GO

-- ====================================
-- Define a file per filegroup as an example
-- ====================================

ALTER DATABASE dbPartitionP15
ADD FILE
(
NAME = Data01_01,
SIZE = 50MB,
MAXSIZE = 50MB,
FILEGROWTH = 10MB
)
TO FILEGROUP Data01;

ALTER DATABASE dbPartitionP15
ADD FILE
(
NAME = Data02_01,
SIZE = 50MB,
MAXSIZE = 50MB,
FILEGROWTH = 10MB
)
TO FILEGROUP Data02;

ALTER DATABASE dbPartitionP15
ADD FILE
(
NAME = Data03_01,
SIZE = 50MB,
MAXSIZE = 50MB,
FILEGROWTH = 10MB
)
TO FILEGROUP Data03;

ALTER DATABASE dbPartitionP15
ADD FILE
(
NAME = Data04_01,
SIZE = 50MB,
MAXSIZE = 50MB,
FILEGROWTH = 10MB
)
TO FILEGROUP Data04;

ALTER DATABASE dbPartitionP15
ADD FILE
(
NAME = Data05_01,
SIZE = 50MB,
MAXSIZE = 50MB,
FILEGROWTH = 10MB
)
TO FILEGROUP Data05;

ALTER DATABASE dbPartitionP15
ADD FILE
(
NAME = Data06_01,
SIZE = 50MB,
MAXSIZE = 50MB,
FILEGROWTH = 10MB
)
TO FILEGROUP Data06;

ALTER DATABASE dbPartitionP15
ADD FILE
(
NAME = Data07_01,
SIZE = 50MB,
MAXSIZE = 50MB,
FILEGROWTH = 10MB
)
TO FILEGROUP Data07;

ALTER DATABASE dbPartitionP15
ADD FILE
(
NAME = Data08_01,
SIZE = 50MB,
MAXSIZE = 50MB,
FILEGROWTH = 10MB
)
TO FILEGROUP Data08;

ALTER DATABASE dbPartitionP15
ADD FILE
(
NAME = Data09_01,
SIZE = 50MB,
MAXSIZE = 50MB,
FILEGROWTH = 10MB
)
TO FILEGROUP Data09;

ALTER DATABASE dbPartitionP15
ADD FILE
(
NAME = Data10_01,
SIZE = 50MB,
MAXSIZE = 50MB,
FILEGROWTH = 10MB
)
TO FILEGROUP Data10;


-- ====================================
-- Create the partition function.
-- ====================================
CREATE PARTITION FUNCTION PF_HASH_BY_VALUE (INT) AS RANGE LEFT
FOR VALUES (100000, 200000, 300000, 400000, 500000, 600000, 700000, 800000, 900000)
SELECT * FROM sys.partition_functions
-- ====================================
-- Create the schema partition.
-- ====================================
CREATE PARTITION SCHEME PS_HASH_BY_VALUE
AS PARTITION PF_HASH_BY_VALUE
TO (Data01,Data02,Data03,Data04,Data05,Data06,Data07,Data08,Data09,Data10);
GO
SELECT * FROM sys.partition_schemes
-- ====================================
-- Configure the Distribution data.
-- ====================================
SELECT
MY_VALUE,
$PARTITION.PF_HASH_BY_VALUE(MY_VALUE) AS HASH_IDX
FROM
(
VALUES
(1),
(100001),
(200001),
(300001),
(400001),
(500001),
(600001),
(700001),
(800001),
(900001)
) AS TEST (MY_VALUE);
GO
-- ====================================
-- Create the table.
-- ====================================
CREATE TABLE [TBL_PARTITION]
( [MY_VALUE] [int] NOT NULL, Age float ,
CONSTRAINT [PK_TBL_PARTITION] PRIMARY KEY CLUSTERED ([MY_VALUE] ASC)
) ON PS_HASH_BY_VALUE ([MY_VALUE])

-- ====================================
-- Add some rows
-- ====================================

DECLARE @nValues AS INTEGER = 0
DECLARE @nFormat AS INTEGER = 0

begin transaction
WHILE @nFormat <10
BEGIN
SET @nFormat = @nFormat +1
SET @nValues = 0
WHILE @nValues<=90000
BEGIN
SET @nValues =@nValues+1
insert into [TBL_PARTITION] (my_value,Age) values(CONVERT(int,CONVERT(varchar(20),@nformat)+CONVERT(varchar(20),@nValues)),RAND())
END
END
commit transaction

-- ====================================
-- Review the partition distribution.
-- ====================================
SELECT object_name(object_id),* FROM sys.dm_db_partition_stats where object_name(object_id)='TBL_PARTITION'
[/code]

Enjoy!