Coding for removing servername from the views.

Source: Internet
Author: User

Coding for removing servername from the views.

 

-- The following script is to find out the existing views of the database machine's display

 

Use Database;

Select

B. Name,

C. referenced_server_name,

C. referenced_database_name,

C. referenced_schema_name,

A. definition,

B. create_date,

B. modify_date

From SYS. SQL _modules as

Join

SYS. Objects as B

On a. object_id = B. object_id

Join

SYS. SQL _expression_dependencies as C

On B. object_id = C. referencing_id

Where B. type = 'V'

And C. referenced_server_name is not null

 

-- The following script is to modify the database view exists after the replacement of the Processing Machine

 

 

Set nocount on;

Declare @ definition varchar (max)

Declare @ servern varchar (50)

Declare view_cursor cursor scroll

For (

Select

C. referenced_server_name,

A. Definition

From SYS. SQL _modules as

Join

SYS. Objects as B

On a. object_id = B. object_id

Join

SYS. SQL _expression_dependencies as C

On B. object_id = C. referencing_id

Where B. type = 'V'

And C. referenced_server_name is not null

)

Open view_cursor;

Fetch next from view_cursor into @ servern, @ definition;

While @ fetch_status = 0

Begin

Select @ definition = Replace (@ definition, 'create view', 'alter view ')

Select @ definition = Replace (@ definition, '[' [email protected] + ']' + '.','')

-- Print (@ definition );

Exec (@ definition );

Fetch next from view_cursor into @ servern, @ definition;

End

Close view_cursor;

Deallocate view_cursor;

Go

 

 

 

Coding for removing servername from the 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.