How to check definition of views in a database

During preparation of replication from remote site to central office I stumbled upon a need to check definitions of all views in a database. The script is simple, yet useful:

select sv.name, sc.text from sys.views sv 
inner join dbo.syscomments sc on sv.object_id = sc.id
where sv.is_ms_shipped = 0 

You get all the non-system views – if you’re looking for a specific text in a script, just drop another conditions in WHERE clause and you’re done. I – for instance – was able to locate all views referencing linked servers.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s