Is it possible to drop an indexed view using SQL Source Control?

I have an existing database with an indexed view that I would like to drop. Unfortunately, my build fails on the "Redgate DLM Automation Build" step with the following error:

[19:20:44][Validating database state] STARTING: Validating database state
[19:20:44][Validating database state] Starting: C:\Program Files (x86)\Red Gate\DLM Automation Suite 1\SC\SQLCompare.exe /include="Identical" /include="StaticData" /scripts1="C:\BuildAgent\temp\buildTmp\SQL CI\te21jk22.mca\db\state" /server2="np:\\.\pipe\LOCALDB#CD36AE7A\tsql\query" /database2="sqlCI_a74f6775-16ac-421a-93d5-774b63b9d099" /synchronize /tempInstance="Data Source=np:\\.\pipe\LOCALDB#CD36AE7A\tsql\query;Integrated Security=True" /options="DecryptPost2KEncryptedObjects,IgnoreFillFactor,IgnoreWhiteSpace,IncludeDependencies,IgnoreFileGroups,IgnoreUserProperties,IgnoreWithElementOrder,IgnoreDatabaseAndServerName,UseCompatibilityLevel,UseMigrationsV2"
[19:20:44][Validating database state] SQL Release: activated, edition: standard, serial number: *********
[19:20:44][Validating database state] SQL Compare Command Line V11.6.0.1493
[19:20:44][Validating database state] ==============================================================================
[19:20:44][Validating database state] Copyright Copyright c 1999 - 2016 Red Gate Software Ltd
[19:20:44][Validating database state] 
[19:20:44][Validating database state] Registering data sources
[19:20:46][Validating database state] Creating mappings
[19:20:46][Validating database state] Comparing[19:20:46][Validating database state] 
[19:20:46][Validating database state] Applying Command Line Items[19:20:46][Validating database state] 
[19:20:46][Validating database state] Checking for identical databases
[19:20:47][Validating database state] Creating SQL[19:20:48][Validating database state] Inserting static data SQL into deployment script
[19:20:48][Validating database state] Deploying changes (from DB1 to DB2)[19:20:48][Validating database state] Error: Synchronization of 'Scripts.state' and
[19:20:48][Validating database state] 'np:\\.\pipe\LOCALDB#CD36AE7A\tsql\query.sqlCI_a74f6775-16ac-421a-93d5-774b63b9d
[19:20:48][Validating database state] 099' failed: Cannot drop the index
[19:20:48][Validating database state] 'dbo.myIndexedView.myClusteredIndex', because it does not
[19:20:48][Validating database state] exist or you do not have permission. Error executing the following SQL: DROP
[19:20:48][Validating database state] INDEX [myClusteredIndex] ON [dbo].[myIndexedView]
[19:20:48][Validating database state] FINISHED WITH ERROR: Validating database state
I see a related issue from several years ago, but I haven't found any follow up: https://forum.red-gate.com/discussion/20122/bug-in-drop-and-create-with-indexed-view

Can anyone help with this issue? At this point, I can't even remove the view manually, since my database builds without the view always fail.
Tagged:

Answers

  • Hi Sam,

    Thanks for your post!

    The issue in that older forum post was resolved in SQL Compare v11.1.7.47 and the version of DLM you're using has the SQL Compare engine from v11.6.0.1493 so the fix for that particular issue should be fixed there. (The problem was that DROP/CREATE instead of ALTER would drop a view then try to refresh it.)

    To confirm though, the index in question does exist in the repository? If you use the latest version of SQL Compare to compare the repository to a blank database, does it fail with the same error?

    Jessica Ramos | Product Support Engineer | Redgate Software

    Have you visited our Help Center?


  • samhanessamhanes Posts: 4 New member
    Thanks for your response Jessica. In this case, we have an existing database with an indexed view, and I have committed a change to our repository to remove both the index and the view. That is, the commit is simply removing the file in the "Views" folder that contains the "CREATE VIEW" and "CREATE INDEX" statements.

    The build step that is failing is the "Redgate DLM Automation Build" - which I believe is creating an empty temporary database to compare against. So the issue is not occurring when we attempt to deploy the db change - we aren't even able to build the package.

    Thanks again for your help!
  • Thanks @samhanes! :)

    The DLM Build step uses SQL Compare behind the scenes to compare the repository to the empty temporary database and see if deploying to the empty database succeeds.

    As DLM uses SQL Compare 12, I just wanted to check if the issue still happens if you manually run that with the latest SQL Compare 13? (in which case the bug should be fixed in SQL Change Automation which replaced DLM).

    If it does still exist in v13 though, we can take a look at the deployment script created to see what's going on.


    Jessica Ramos | Product Support Engineer | Redgate Software

    Have you visited our Help Center?


  • samhanessamhanes Posts: 4 New member
    Thanks @Jessica R - I don't have a license for SQL Compare, and our infrastructure team isn't able to upgrade the DLM Build component right now. We are going to explore other options for now - thanks again for your help.
  • Ah ok, no worries! Just let us know if you'd like to return to this down the line.

    Jessica Ramos | Product Support Engineer | Redgate Software

    Have you visited our Help Center?


Sign In or Register to comment.