Uwaga
Dostęp do tej strony wymaga autoryzacji. Może spróbować zalogować się lub zmienić katalogi.
Dostęp do tej strony wymaga autoryzacji. Możesz spróbować zmienić katalogi.
Dotyczy:SQL Server
Azure SQL Database
Azure SQL Managed Instance
Azure Synapse Analytics
Baza danych SQL w usłudze Microsoft Fabric (wersja zapoznawcza)
Dane mogą być przechowywane przy użyciu algorytmów magazynu udostępnianych przez tabele i indeksy partycjonowane. Partycjonowanie może sprawić, że duże tabele i indeksy będą bardziej zarządzane i skalowalne.
Partycjonowanie indeksów i tabel
Funkcja umożliwia rozłożenie danych indeksów i tabel w wielu grupach plików w partycjach. Funkcja partycji definiuje sposób mapowania wierszy tabeli lub indeksu na zestaw partycji na podstawie wartości określonych kolumn, nazywanych kolumnami partycjonowania. Schemat partycji mapuje każdą partycję określoną przez funkcję partycji na grupę plików. Dzięki temu można opracowywać strategie archiwizowania, które umożliwiają skalowanie tabel w grupach plików, a tym samym na urządzeniach fizycznych.
Obiekt Database zawiera kolekcję PartitionFunction obiektów reprezentujących zaimplementowane funkcje partycji i kolekcję PartitionScheme obiektów opisujących sposób mapowania danych na grupy plików.
Każdy Table obiekt i Index określa schemat partycji używany we PartitionScheme właściwości i określa kolumny w obiekcie PartitionSchemeParameterCollection.
Example
W poniższych przykładach kodu należy wybrać środowisko programowania, szablon programowania i język programowania, aby utworzyć aplikację. Aby uzyskać więcej informacji, zobacz Create a Visual C# SMO Project in Visual Studio .NET(Tworzenie projektu SMO w programie Visual Studio .NET).
Konfigurowanie schematu partycji dla tabeli w programie Visual C#
W przykładzie kodu pokazano, jak utworzyć funkcję partycji i schemat partycji dla TransactionHistory
tabeli w przykładowej bazie danych AdventureWorks2022. Partycje są podzielone według daty z zamiarem oddzielenia starych rekordów do TransactionHistoryArchive
tabeli.
{
//Connect to the local, default instance of SQL Server.
Server srv;
srv = new Server();
//Reference the AdventureWorks2022 database.
Database db;
db = srv.Databases("AdventureWorks2022");
//Define and create three new file groups on the database.
FileGroup fg2;
fg2 = new FileGroup(db, "Second");
fg2.Create();
FileGroup fg3;
fg3 = new FileGroup(db, "Third");
fg3.Create();
FileGroup fg4;
fg4 = new FileGroup(db, "Fourth");
fg4.Create();
//Define a partition function by supplying the parent database and name arguments in the constructor.
PartitionFunction pf;
pf = new PartitionFunction(db, "TransHistPF");
//Add a partition function parameter that specifies the function uses a DateTime range type.
PartitionFunctionParameter pfp;
pfp = new PartitionFunctionParameter(pf, DataType.DateTime);
pf.PartitionFunctionParameters.Add(pfp);
//Specify the three dates that divide the data into four partitions.
object[] val;
val = new object[] {"1/1/2003", "1/1/2004", "1/1/2005"};
pf.RangeValues = val;
//Create the partition function.
pf.Create();
//Define a partition scheme by supplying the parent database and name arguments in the constructor.
PartitionScheme ps;
ps = new PartitionScheme(db, "TransHistPS");
//Specify the partition function and the filegroups required by the partition scheme.
ps.PartitionFunction = "TransHistPF";
ps.FileGroups.Add("PRIMARY");
ps.FileGroups.Add("second");
ps.FileGroups.Add("Third");
ps.FileGroups.Add("Fourth");
//Create the partition scheme.
ps.Create();
}
Konfigurowanie schematu partycji dla tabeli w programie PowerShell
W przykładzie kodu pokazano, jak utworzyć funkcję partycji i schemat partycji dla TransactionHistory
tabeli w przykładowej bazie danych AdventureWorks2022. Partycje są podzielone według daty z zamiarem oddzielenia starych rekordów do TransactionHistoryArchive
tabeli.
# Set the path context to the local, default instance of SQL Server.
CD \sql\localhost\default
#Get a server object which corresponds to the default instance
$srv = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Server
$db = $srv.Databases["AdventureWorks"]
#Create four filegroups
$fg1 = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Filegroup -argumentlist $db, "First"
$fg2 = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Filegroup -argumentlist $db, "Second"
$fg3 = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Filegroup -argumentlist $db, "Third"
$fg4 = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Filegroup -argumentlist $db, "Fourth"
#Define a partition function by supplying the parent database and name arguments in the constructor.
$pf = New-Object -TypeName Microsoft.SqlServer.Management.SMO.PartitionFunction -argumentlist $db, "TransHistPF"
$T = [Microsoft.SqlServer.Management.SMO.DataType]::DateTime
$T
$T.GetType()
#Add a partition function parameter that specifies the function uses a DateTime range type.
$pfp = New-Object -TypeName Microsoft.SqlServer.Management.SMO.PartitionFunctionParameter -argumentlist $pf, $T
#Specify the three dates that divide the data into four partitions.
#Create an array of type object to hold the partition data
$val = "1/1/2003"."1/1/2004","1/1/2005"
$pf.RangeValues = $val
$pf
#Create the partition function
$pf.Create()
#Create partition scheme
$ps = New-Object -TypeName Microsoft.SqlServer.Management.SMO.PartitionScheme -argumentlist $db, "TransHistPS"
$ps.PartitionFunction = "TransHistPF"
#add the filegroups to the scheme
$ps.FileGroups.Add("PRIMARY")
$ps.FileGroups.Add("Second")
$ps.FileGroups.Add("Third")
$ps.FileGroups.Add("Fourth")
#Create it at the server
$ps.Create()