i want to move a table to a new filegroup. Using the accepted answer as a starting point:
CREATE CLUSTERED INDEX CIX_YourTable
ON dbo.YourTable(YourClusteringKeyFields)
WITH DROP_EXISTING
ON [filegroup_name]
i adapt it to my use:
CREATE CLUSTERED INDEX PK_AuditLog_AuditLogID
ON dbo.AuditLog(AuditLogID)
WITH DROP_EXISTING
ON [TheOtherFileGroup]
gives the error:
Msg 1907, Level 16, State 1, Line 1
Cannot recreate index 'PK_AuditLog_AuditLogID'. The new index definition does not match the constraint being enforced by the existing index.
This is, i assume, because PK_AuditLog_AuditLogID
is
So i need the syntax to create a primary key clustered index WITH DROP_EXISTING
On the Table Designer menu, click Indexes/Keys. In the Indexes/Keys dialog box, click Add. Select the new index in the Selected Primary/Unique Key or Index text box. In the grid, select Create as Clustered, and choose Yes from the drop-down list to the right of the property.
A clustered index defines the order in which data is physically stored in a table. Table data can be sorted in only way, therefore, there can be only one clustered index per table. In SQL Server, the primary key constraint automatically creates a clustered index on that particular column.
Select the field or fields that you want to use as the primary key. To select one field, click the row selector for the field you want. To select more than one field to create a composite key, hold down CTRL and then click the row selector for each field.
CREATE UNIQUE CLUSTERED INDEX PK_AuditLog_AuditLogID
ON dbo.AuditLog(AuditLogID)
WITH DROP_EXISTING
ON [TheOtherFileGroup]
The logical primary key constraint is preserved (though tested in 2012)
CREATE TABLE dbo.AuditLog
(
AuditLogID int constraint PK_AuditLog_AuditLogID primary key
)
CREATE UNIQUE CLUSTERED INDEX PK_AuditLog_AuditLogID
ON dbo.AuditLog(AuditLogID)
WITH DROP_EXISTING
ON [Primary]
SELECT CONSTRAINT_TYPE /*Returns PRIMARY KEY*/
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
WHERE CONSTRAINT_NAME = 'PK_AuditLog_AuditLogID'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With