Alter view taking time more than expected

dinesh 41 Reputation points
2022-05-24T00:12:22.04+00:00

Hi, I have to alter a view. We ran that view in production For some reason, it took 1:05 time. After that jobs depending on that view started failing. No issue with jobs. We thought some issue with view.

We restored old production db backup copy in lower lanes and ran that view, it took a min.

We are trying to understand what would be the issue. How do we fix issue in production? What are all different things need to consider to fix the issue.

Any help is really appreciate

SQL Server | Other
{count} votes

2 answers

Sort by: Most helpful
  1. Olaf Helper 47,436 Reputation points
    2022-05-24T05:05:05.98+00:00

    We are trying to understand what would be the issue.

    Altering a view (or any other database object) requires an exclusive access on it and as long as an other process accesses the view, you can not alter it and have to wait, till no other process accesses it.

    0 comments No comments

  2. Seeya Xi-MSFT 16,586 Reputation points
    2022-05-24T07:03:38.803+00:00

    Hi @dinesh ,

    Welcome to Microsoft Q&A!

    jobs depending on that view started failing, ran that view, it took a min

    We need to know if the view is being used inappropriately.

    1. Check View Dependencies

    • In SQL Server Management Studio, look for YourDatabase.
    • Expand the Views folder and look for YourView.
    • Right-click it and select View Dependencies.
      Try not to have a situation where one view depends on another view.

    2. See Actual Execution Plan

    3. Try Indexed Views
    It can give a performance boost to SELECT statements. But like table indexes, it can impact performance if the base tables are large and continuously updated. Also, check the STATISTICS IO if there’s a decrease in logical reads after adding the index.

    For more information, please read this article: https://codingsight.com/top-3-tips-you-need-to-know-to-write-faster-sql-views/

    Best regards,
    Seeya


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.