Two ways to refresh the associated view after modifying the basic table

Source: Internet
Author: User
Microsoft version:

Microsoft described this as "used to update the metadata of the specified view not bound to the architecture. Due to changes to the basic object on which the view depends, the persistent metadata of the view will expire .", I didn't understand the first half of the sentence.

USE AdventureWorks;GOSELECT DISTINCT 'EXEC sp_refreshview ''' + name + '''' FROM sys.objects AS so INNER JOIN sys.sql_expression_dependencies AS sed     ON so.object_id = sed.referencing_id WHERE so.type = 'V' AND sed.referenced_id = OBJECT_ID('Person.Contact');

'Person. contact' is the basic table we modified. Refresh all views dependent on this table.

Get a similar

Exec sp_refreshview 'view1'
Exec sp_refreshview 'view2'
Exec sp_refreshview 'view3'

Exec sp_refreshview 'view4'

This list is copied and executed manually.

Network Version:
CREATE PROCEDURE RefreshAllView ASDECLARE MyCursor CURSORFOR select Name from dbo.sysobjects where  OBJECTPROPERTY(id, N'IsView') = 1 and (not name in ('sysconstraints','syssegments'))DECLARE @name varchar(40)OPEN MyCursorFETCH NEXT FROM MyCursor INTO @nameWHILE (@@fetch_status <> -1)BEGIN    IF (@@fetch_status <> -2)    begin     exec sp_refreshview @name             end    FETCH NEXT FROM MyCursor INTO @nameENDCLOSE MyCursorDEALLOCATE MyCursor

Network from: http://www.cnblogs.com/yashen/archive/2004/12/23/81000.html

Generates a stored procedure and automatically refreshes all views.

 

 

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.