PARTITION TABLE
You can create a partitioned table or index in SQL Server.The data in partitioned tables or indexes divided into two different data set for given table.Using following T-SQL commands will help you to partition tables.
USE [master]GOALTER DATABASE [DATABASEUSERGROUP] ADD FILEGROUP [SALES];GOALTER DATABASE [DATABASEUSERGROUP] ADD FILEGROUP [ARCHIVE_OLD];GOALTER DATABASE [DATABASEUSERGROUP] ADD FILEGROUP [ARCHIVE_2002];GOALTER DATABASE [DATABASEUSERGROUP] ADD FILEGROUP [ARCHIVE_2003];GOALTER DATABASE [DATABASEUSERGROUP] ADD FILE ( NAME = N'SALES_01',FILENAME = N'C:\MSSQL\2016\Sales_01.ndf' ,SIZE = 1024KB ,FILEGROWTH = 1024KB ) TO FILEGROUP [SALES];GOALTER DATABASE [DATABASEUSERGROUP] ADD FILE ( NAME = N'ARCHIVE_OLD',FILENAME = N'C:\MSSQL\2016\Archive_Old_01.ndf' ,SIZE = 1024KB ,FILEGROWTH = 1024KB ) TO FILEGROUP [ARCHIVE_OLD];GOALTER DATABASE [DATABASEUSERGROUP] ADD FILE ( NAME = N'ARCHIVE_2002',FILENAME = N'C:\MSSQL\2016\Archive_2002_01.ndf' ,SIZE = 1024KB ,FILEGROWTH = 1024KB ) TO FILEGROUP [ARCHIVE_2002];GOALTER DATABASE [DATABASEUSERGROUP] ADD FILE ( NAME = N'ARCHIVE_2003',FILENAME = N'C:\MSSQL\2016\Archive_2003_01.ndf' ,SIZE = 1024KB ,FILEGROWTH = 1024KB ) TO FILEGROUP [ARCHIVE_2003];GOUSE [DATABASEUSERGROUP]GOIF NOT EXISTS (SELECT * FROM sys.partition_functions WHERE name = N'pf_year_archive') BEGINCREATE PARTITION FUNCTION [pf_year_archive](tinyint) AS RANGE LEFT FOR VALUES (0, 1, 2, 3)ENDGOIF NOT EXISTS (SELECT * FROM sys.partition_schemes WHERE name = N'ps_year_archive') BEGINCREATE PARTITION SCHEME [ps_year_archive] AS PARTITION [pf_year_archive]TO ([SALES], [ARCHIVE_OLD], [ARCHIVE_2002], [ARCHIVE_2003], [SALES])ENDGOALTER TABLE [DATABASEUSERGROUP].[dbo].[SalesOrderDetail] ADD archive tinyint DEFAULT(0) NOT NULL;--ALTER TABLE [DATABASEUSERGROUP].[dbo].[SalesOrderDetail] DROP COLUMN archive ;GOIF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[SalesOrderDetail]') AND name = N'CIX_SalesOrderDetail_ProductID') BEGINCREATE CLUSTERED INDEX [CIX_SalesOrderDetail_ProductID] ON [dbo].[SalesOrderDetail]([ProductID] ASC) ON [ps_year_archive]([archive]);ENDGOSELECT * FROM [DATABASEUSERGROUP].[dbo].[SalesOrderDetail];GOSELECT * FROM sys.dm_db_partition_stats WHERE object_id = OBJECT_ID('dbo.SalesOrderDetail');GOUPDATE [DATABASEUSERGROUP].[dbo].[SalesOrderDetail] SET archive=1 WHERE YEAR(ModifiedDate)<2002;GOSELECT * FROM sys.dm_db_partition_stats WHERE object_id = OBJECT_ID('dbo.SalesOrderDetail');GOUPDATE [DATABASEUSERGROUP].[dbo].[SalesOrderDetail] SET archive=2 WHERE YEAR(ModifiedDate)=2002;GOSELECT * FROM sys.dm_db_partition_stats WHERE object_id = OBJECT_ID('dbo.SalesOrderDetail');GOUPDATE [DATABASEUSERGROUP].[dbo].[SalesOrderDetail] SET archive=3 WHERE YEAR(ModifiedDate)=2003;GOSELECT * FROM sys.dm_db_partition_stats WHERE object_id = OBJECT_ID('dbo.SalesOrderDetail');GOUPDATE [DATABASEUSERGROUP].[dbo].[SalesOrderDetail] SET archive=4 WHERE SalesOrderID=61184;GO
Cheers...
and Most welcome your comments and ideas...
and Most welcome your comments and ideas...