sql-server – SQL Azure与聚簇索引和删除约束有关的问题

我有以下SQL脚本似乎在本地SQL 2008 R2实例上工作但在Azure SQL上失败.

我已经搜索过网络,但还没有找到任何解决方案.

有什么建议?

我想避免使用Identity列.

CREATE TABLE dbo.[Category]
(
    CategoryId NVARCHAR(36),
    CONSTRAINT PK_Category_CategoryId PRIMARY KEY CLUSTERED(CategoryId)
)
GO
CREATE TABLE dbo.[File]
(
    FileId NVARCHAR(36),
    CONSTRAINT PK_File_FileId PRIMARY KEY CLUSTERED(FileId)
)
GO
CREATE TABLE dbo.[FileCategory]
(
    FileId NVARCHAR(36),
    CategoryId NVARCHAR(36)
    CONSTRAINT FK_FileCategory_FileId FOREIGN KEY (FileId) REFERENCES [File](FileId) ON DELETE CASCADE,
    CONSTRAINT FK_FileCategory_CategoryId FOREIGN KEY (CategoryId) REFERENCES [Category](CategoryId) ON DELETE CASCADE,
)
GO
INSERT INTO [Category] VALUES('ABC')
INSERT INTO [Category] VALUES('DEF')
INSERT INTO [Category] VALUES('GHI')
GO

以上运行正常,但在以下语句中失败,错误如下所示:

DELETE FROM [Category] WHERE [CategoryId] = 'ABC'

Msg 40054, Level 16, State 1, Line 3 Tables without a clustered index
are not supported in this version of SQL Server. Please create a
clustered index and try again.

最佳答案 尝试在FileCategory上设置PRIMARY KEY –

CREATE TABLE [dbo].[FileCategory]
(
    [FileId] [nvarchar](36) NOT NULL,
    [CategoryId] [nvarchar](36) NOT NULL,
     CONSTRAINT [PK_FileCategory] PRIMARY KEY CLUSTERED 
    (
        [FileId], [CategoryId]
    ) ON [PRIMARY]
) ON [PRIMARY]
点赞