修改資料分割配置

適用於:SQL ServerAzure SQL DatabaseAzure SQL 受控執行個體

您可以指定檔案群組來保存使用SQL Server Management Studio (SSMS) 或 Transact-SQL 新增至分割資料表的下一個分割區,來修改 SQL Server、Azure SQL Database 和 Azure SQL 受控執行個體中的資料分割配置。 作法是,將 NEXT USED 屬性指派給檔案群組。

NEXT USED 屬性可以指派給空的檔案群組或已保存資料分割的檔案群組。 換句話說,檔案群組可以保存一個以上的資料分割。 深入了解檔案群組中的檔案群組和資料分割策略。

也可以在 Azure Synapse Analytics 的專用 SQL 集區中分割資料表,但語法會有一些差異。 深入了解專用 SQL 集區中的資料分割資料表

限制

只要是 ALTER PARTITION SCHEME 影響所及的檔案群組都必須在線上。

注意

Azure SQL Database 僅支援 PRIMARY 檔案群組。

權限

您可以使用下列權限來執行 ALTER PARTITION SCHEME:

  • ALTER ANY DATASPACE 權限。 這個權限預設會授與 sysadmin 固定伺服器角色以及 db_ownerdb_ddladmin 固定資料庫角色的成員。

  • 建立資料分割結構描述之資料庫的 CONTROL 或 ALTER 權限。

  • 在建立資料分割結構描述的資料庫中,其伺服器的 CONTROL SERVER 或 ALTER ANY DATABASE 權限。

使用 Transact-SQL 修改資料分割配置

這個範例會使用 AdventureWorks 範例資料庫

  1. 在物件總管中,連線到資料庫引擎的執行個體。

  2. 在標準列上,選取 [新增查詢] 。

  3. 複製下列範例並將其貼到查詢視窗中,然後選取 [執行]。

    注意

    為了簡單起見,此程式碼會建立新的檔案群組,但不會為其指派檔案。 如此一來,就可以示範如何修改資料分割配置,但不是設定分割物件的完整範例。 在建立資料分割資料表和索引中尋找建立分割資料表和索引的範例。

    USE AdventureWorks2022;  
    GO
    -- add five new filegroups to the AdventureWorks2022 database  
    ALTER DATABASE AdventureWorks2022  
    ADD FILEGROUP test1fg;  
    GO  
    ALTER DATABASE AdventureWorks2022  
    ADD FILEGROUP test2fg;  
    GO  
    ALTER DATABASE AdventureWorks2022  
    ADD FILEGROUP test3fg;  
    GO  
    ALTER DATABASE AdventureWorks2022  
    ADD FILEGROUP test4fg;  
    GO  
    ALTER DATABASE AdventureWorks2022  
    ADD FILEGROUP test5fg;  
    GO 
    
    -- if the "myRangePF1" partition function and the "myRangePS1" partition scheme exist,  
    -- drop them from the AdventureWorks2022 database  
    IF EXISTS (SELECT * FROM sys.partition_functions  
        WHERE name = 'myRangePF1')  
    DROP PARTITION FUNCTION myRangePF1;  
    GO  
    IF EXISTS (SELECT * FROM sys.partition_schemes  
        WHERE name = 'myRangePS1')  
    DROP PARTITION SCHEME myRangePS1;  
    GO  
    
    -- create the new partition function "myRangePF1" with four partition groups  
    CREATE PARTITION FUNCTION myRangePF1 (int)  
    AS RANGE LEFT FOR VALUES ( 1, 100, 1000 );  
    GO  
    
    -- create the new partition scheme "myRangePS1"that will use   
    -- the "myRangePF1" partition function with five file groups.  
    -- The last filegroup, "test5fg," will be kept empty but marked  
    -- as the next used filegroup in the partition scheme.  
    CREATE PARTITION SCHEME myRangePS1  
    AS PARTITION myRangePF1  
    TO (test1fg, test2fg, test3fg, test4fg, test5fg);  
    GO  
    
    --Split "myRangePS1" between boundary_values 100 and 1000  
    --to create two partitions between boundary_values 100 and 500  
    --and between boundary_values 500 and 1000.  
    ALTER PARTITION FUNCTION myRangePF1 ()  
    SPLIT RANGE (500);  
    GO  
    
    -- Allow the "myRangePS1" partition scheme to use the filegroup "test5fg"  
    -- for the partition with boundary_values of 100 and 500  
    ALTER PARTITION SCHEME myRangePS1  
    NEXT USED test5fg;  
    GO  
    

使用 SSMS 刪除資料分割配置

  1. 在 [物件總管] 中,連線到您的目標資料庫。

  2. 選取加號,展開您想要在其中刪除資料分割配置的資料庫。

  3. 選取加號展開 [儲存體] 資料夾。

  4. 選取加號展開 [資料分割配置] 資料夾。

  5. 以滑鼠右鍵按一下您想要刪除的資料分割配置,然後選取 [刪除]

  6. 在 [刪除物件] 對話方塊中,確定已選取正確的資料分割配置,然後選取 [確定]。

下一步

閱讀下列文章深入了解資料表分割: