Search code examples
sqlazureazure-sql-databaseclustered-index

SQL Azure not recognizing my clustered Index


I get the following error when I try to insert a row into a SQL Azure table.

Tables without a clustered index are not supported in this version of SQL Server. Please create a clustered index and try again.

My problem is I do have a clustered index on that table. I used SQL Azure MW to generate the Azure SQL Script.

Here's what I'm using:

IF  EXISTS (SELECT * FROM sys.objects
    WHERE object_id = OBJECT_ID(N'[dbo].[tblPasswordReset]') AND type in (N'U'))
DROP TABLE [dbo].[tblPasswordReset]
GO
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
IF NOT EXISTS (SELECT * FROM sys.objects
    WHERE object_id = OBJECT_ID(N'[dbo].[tblPasswordReset]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[tblPasswordReset](
    [PasswordResetID] [int] IDENTITY(1,1) NOT NULL,
    [PasswordResetGUID] [uniqueidentifier] NULL,
    [MemberID] [int] NULL,
    [RequestDate] [datetime] NULL,
 CONSTRAINT [PK_tblPasswordReset] PRIMARY KEY CLUSTERED 
(
    [PasswordResetID] ASC
)WITH (STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF)
)
END
GO

Why doesn't SQL Azure recognize my clustered Key? Is my script wrong?


Solution

  • Your script only creates the table if it did not exist yet. Perhaps there still is an old version of the table without a clustered index? You can check with:

    select * from sys.indexes where object_id = object_id('tblPasswordReset')
    

    If the table exists without the clustered index, you can add one like:

    alter table tblPasswordReset add constraint
        PK_tblPasswordReset primary key clustered
    

    As far as I can see, your statement does conform to the Azure create table spec.