Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 262149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:29:29+00:00 2026-05-11T22:29:29+00:00

I was just prototyping a new system for deferring certain operations until out of

  • 0

I was just prototyping a new system for deferring certain operations until out of hours on one of our databases. I’ve come up with (what I think) a pretty simple schema. I was first prototyping on SQL Server 2005 Express, but have confirmed the same problem on 2008 Developer. The error I’m getting is:

Msg 8646, Level 21, State 1, Procedure
Cancel, Line 6 Unable to find index
entry in index ID 1, of table
277576027, in database ‘xxxxxx’. The
indicated index is corrupt or there is
a problem with the current update
plan. Run DBCC CHECKDB or DBCC
CHECKTABLE. If the problem persists,
contact product support.

The schema I’m using is:

create schema Writeback authorization dbo
    create table Deferrals (
        ClientID uniqueidentifier not null,
        RequestedAt datetime not null,
        CompletedAt datetime null,
        CancelledAt datetime null,
        ResolvedAt as ISNULL(CompletedAt,CancelledAt) persisted,
        constraint PK_Writeback_Deferrals PRIMARY KEY (ClientID,RequestedAt) on [PRIMARY],
        constraint CK_Writeback_Deferrals_NoTimeTravel CHECK ((RequestedAt <= CompletedAt) AND (RequestedAt <= CancelledAt)),
        constraint CK_Writeback_Deferrals_NoSchrodinger CHECK ((CompletedAt is null) or (CancelledAt is null))
        /* TODO:FOREIGN KEY */
    )
    create view Pending with schemabinding as
    select
        ClientID
    from
        Writeback.Deferrals
    where
        ResolvedAt is null
go
alter table Writeback.Deferrals add constraint
    DF_Writeback_Deferrals_RequestedAt DEFAULT CURRENT_TIMESTAMP for RequestedAt
go
create unique clustered index PK_Writeback_Pending on Writeback.Pending (ClientID)
go
create procedure Writeback.Defer
    @ClientID uniqueidentifier
as
    set nocount on

    insert into Writeback.Deferrals (ClientID)
    select @ClientID
    where not exists(select * from Writeback.Pending where ClientID = @ClientID)
go
create procedure Writeback.Cancel
    @ClientID uniqueidentifier
as
    set nocount on

    update
        Writeback.Deferrals
    set
        CancelledAt = CURRENT_TIMESTAMP
    where
        ClientID = @ClientID and
        CompletedAt is null and
        CancelledAt is null
go
create procedure Writeback.Complete
    @ClientID uniqueidentifier
as
    set nocount on

    update
        Writeback.Deferrals
    set
        CompletedAt = CURRENT_TIMESTAMP
    where
        ClientID = @ClientID and
        CompletedAt is null and
        CancelledAt is null
go

And the code that provokes the error is as follows:

declare @ClientA uniqueidentifier
declare @ClientB uniqueidentifier
select @ClientA = newid(),@ClientB = newid()

select * from Writeback.Pending
exec Writeback.Defer @ClientA
select * from Writeback.Pending
exec Writeback.Defer @ClientB
select * from Writeback.Pending
exec Writeback.Cancel @ClientB  --<-- Error being raised here
select * from Writeback.Pending
exec Writeback.Complete @ClientA
select * from Writeback.Pending
select * from Writeback.Deferrals

I’ve seen a few others encountering such problems, but they seem to either have aggregates in their views (and a message back from MS saying they’d remove the ability to create such indexed views in 2005 SP 1), or they resolved it by applying a merge join in their join clause (but I don’t have one).

Initially there was no computed column in the Deferrals table, and the where clause in the view was testing the CompletedAt and CancelledAt columns for NULL separately. But I changed to the above just to see if I could provoke different behaviour.

All of my SET options look right for using indexed views, and if they weren’t, I’d expect a less violent error to be thrown.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T22:29:29+00:00Added an answer on May 11, 2026 at 10:29 pm

    I managed to work out what’s causing this error, by trying to build up this script, from scratch, adding in pieces as I went.

    It’s some kind of bug that’s produced if the view is created as part of a CREATE SCHEMA statement. If I separate the CREATE SCHEMA into it’s own batch, and then create the table and view in separate batches, everything works fine.


    Long overdue edit – I raised this on Connect here. It was confirmed as being an issue in SQL Server 2008.

    Internal builds (in 2010) indicated it was no longer an issue, and I have (just now, 2016) confirmed that the script in the question does not generate the same error in SQL Server 2012. The fix was not back-ported to SQL Server 2008.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just out of curiosity, how does iostream access the input-output system. (I have a
Just trying to get diff to work better for certain kinds of documents. With
I'm prototyping a concurrent/distributed system in Java. When a process is terminated (e.g. ctrl+c
I've searched for at question like this and i dont think there are one.
Just doing some testing/prototyping with ClickOnce. Does anyone know why I can publish with
Just a curiosity, I have played around with prototyping a bit, but it seems
I have been racking my brain on this one for hours now and I
just a quick one - can anyone advise how I can alter the version
Just wondering is there any way to open a webpage in new tab inside
I created just the most basic WCF Service Application to do some prototyping, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.