4

I have the following SQL script that seems to work on local SQL 2008 R2 instance but fails on Azure SQL.

I have scoured the web but have not found any solution yet.

Any suggestions?

I would like to avoid Identity columns.

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

The above runs fine however it fails on the following statement with the error shown below:

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.

1 Answer 1

1

Try to set PRIMARY KEY on FileCategory -

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]
Sign up to request clarification or add additional context in comments.

3 Comments

Adding the CONSTRAINT with ON [PRIMARY] results in Msg 40514, Level 16, State 1, Line 23 'Filegroup reference and partitioning scheme' is not supported in this version of SQL Server. Removing ON PRIMARY works but will this still support delete cascades?
Sorry, but I didn't mean that. I just proposed add a composite PK.
My apologies. I guess you meant to say that include the Primary Key constraint on FileCategory (in addition to the Foreign Key constraint) Having both constraints worked. Thanks,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.