简体   繁体   中英

Partitioned Graph table - Partition Switch failed

I am trying and partitioning to an existing SQL Server Graph table (node). The table is very large and is taking long time for deletes etc, so hoping to use partitioning to improve the performance.

However, when I add partition and try to SWITCH the data. It fails with the below error:

Msg 7733, Level 16, State 4, Line 1 'ALTER TABLE SWITCH' statement failed. The table tempdatabase.dbo.graphtable is partitioned while index 'GRAPH_UNIQUE_INDEX_xxxxxxxxx' is not partitioned.

As the index GRAPH_UNIQUE_INDEX_xxxxxxxxx is automatically created, not able to add the partition key it.

CREATE PARTITION FUNCTION f_partfunction (INT) AS RANGE LEFT 
FOR VALUES (1,100,200,300)
GO

-- Create the partition scheme
CREATE PARTITION SCHEME s_partscheme
AS PARTITION f_partfunction
ALL TO ([PRIMARY]);
GO


CREATE TABLE [dbo].[graphtable](
    PartitionKey INT,
    ID INT,
    EName varchar(100))
 AS NODE  ON s_partscheme (PartitionKey)
go

CREATE TABLE [dbo].[graphtable_test](
    PartitionKey INT,
    ID INT,
    EName varchar(100))
 go

 --Failing Code
 ALTER TABLE [dbo].[graphtable] SWITCH PARTITION 3 TO [dbo].[graphtable_test]

You will have to drop the current index, and then recreate with the index pointing to the partition schema you have.

    CREATE INDEX GRAPH_UNIQUE_INDEX_xxxxxxxxx' ON graphtable
    (
    "Your column"
    )
    INCLUDE (  [Primary Key column]) WITH (DATA_COMPRESSION = PAGE) ON
    [s_partscheme] (PartitionKey)
    GO

In your case l'm guessing its PartitionKey, used as Partition column.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM