Search views in multiple MS SQL databases for use of Order BY and record which view uses it

0

In the process of migrating over some old databases to new servers, we know that some views in some databases might be using an ORDER BY, but we're unsure which / where. We'd like to record which views in which databases are using it (or at least which databases) so that we can reach out to people whose code might need to be updated in the future.

Is there a clever way of automating this?

Thanks in advance,

user49438

Posted 2015-06-12T15:51:34.687

Reputation: 123

Answers

0

This code will show views with the specified clause:

SELECT v.name, m.definition    
FROM sys.views v
INNER JOIN sys.sql_modules m ON m.object_id = v.object_id
where m.definition like '%ORDER BY%'

Or you could script out all views to a window and search by text in the editor.

Paul

Posted 2015-06-12T15:51:34.687

Reputation: 203