SQL Azure not recognizing my clustered Index

房东的猫 提交于 2019-12-07 09:20:09

问题


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?


回答1:


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.




回答2:


Be careful if you're using SSIS. I ran into this same problem, myself, but was using SSIS instead of manually inserting the data. By default SSIS will drop and recreate the table, so even though I had it properly defined with a clustered index, my SSIS script failed. On the "Edit Mappings" step in the SSIS wizard you can manually define the table creation script. I just deleted the table gen script there and my import worked.

(I'd leave this as a comment but my post count is too anemic)



来源:https://stackoverflow.com/questions/7224043/sql-azure-not-recognizing-my-clustered-index

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!