Home » Topic » Clustered Index Issue In SQL Server 2005

Clustered Index Issue In SQL Server 2005

Andrew Jackson ~ Modified: July 11th, 2015 ~ ~ 1 Minute Reading

Home Forums Clustered Index Issue In SQL Server 2005

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #357 Score: 0
    Lincoln Burrows
    Moderator
    16 pts

    You must run the DBCC CHECKDB and find the causes of the error in the error log file otherwise restore from full backup.

    #540 Score: 0
    Stephen West
    Moderator
    4 pts

    First, you have to create any additional indexes on the table as non-clustered.

      CREATE NONCLUSTERED INDEX [IX_Directory_AreaCode_PhoneNumber]
      ON [dbo].[Directory] ( [AreaCode], [PhoneNumber] )
      GO

    If you want to change how the table is clustered, you have to drop the existing clustered index first before you can create a new one.

      ALTER TABLE [dbo].[Directory]
      DROP CONSTRAINT [PK_Directory]
      GO
      CREATE CLUSTERED INDEX [IX_Directory_AreaCode_PhoneNumber]
      ON [dbo].[Directory] ( [AreaCode], [PhoneNumber] )
      GO
      ALTER TABLE [dbo].[Directory]
      ADD CONSTRAINT [PK_Directory] PRIMARY KEY ( [LastName], [FirstName] )
      GO

    Since the [dbo].[Directory] already have a clustered index, the PRIMARY KEY constraint defaults to NONCLUSTERED.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.