Can you move a table to new Filegroup/File without removing PK?

  • These are the steps I was going to take:

    --step 1

    ALTER TABLE Orders.dbo.tbl_OrdersArchive

    DROP CONSTRAINT [PK_tbl_OrdersArchive] WITH (MOVE TO SECONDARY)

    --step 2

    ALTER TABLE Orders.dbo.tbl_OrdersArchive

    ADD CONSTRAINT [PK_tbl_OrdersArchive] PRIMARY KEY CLUSTERED

    ( [OrdersID] ASC

    )WITH (IGNORE_DUP_KEY = OFF) ON [SECONDARY]

    Can this be done without removing the Primary Key?

    Thanks,

    DK

  • Maybe I should have included this in the OP, but I am aware that I can do an insert/select to a temp table and then rename, but I am worried about missing transations, and putting the database in a single user mode would render the same affect as using the Drop/recreate PK route, i.e... users not able to carry on business operations while this is taking place.

    I also came across the "WITH (DROP_EXISTING=ON, ONLINE=ON)" but I can not use Online=On option because one of the columns in the table has xml. Plus, the PK issue.

    Thanks,

    David

  • Does the PK have a clustered index upon it at present?

    -----------------------------------------------------------------------------------------------------------

    "Ya can't make an omelette without breaking just a few eggs" 😉

  • Yes, it does.

    Thanks.

  • In that case you use CREATE INDEX specifying the new file group with the DROP_EXISTING = ON clause

    See here for more detail

    -----------------------------------------------------------------------------------------------------------

    "Ya can't make an omelette without breaking just a few eggs" 😉

  • Thanks.

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply