Trojan.ZBOT
Trojan.ZBOT

Reputation: 1488

Searching for a view or any object in SQL Server?

I need to find a view in SQL Server 2000, 2005 and 2008. Actually, I'd like to be able to find anything using a simple query. I tried one answer which did not work - How can I check if a View exists in a Database?

Is there a script to search for views or any other object that is guaranteed to work in all SQL Server versions I mentioned? I prefer something which does not need you to know table names and such to find a view.

Upvotes: 2

Views: 10680

Answers (2)

lopushen
lopushen

Reputation: 1137

you may need this query

SELECT TABLE_NAME as ViewName,
VIEW_DEFINITION as ViewDefinition
FROM INFORMATION_SCHEMA.Views

Upvotes: 2

Martin Smith
Martin Smith

Reputation: 453298

If you need SQL Server 2000 compatibility (so sys.views is not available) you can query INFORMATION_SCHEMA.VIEWS

For other types of objects the SQL Server 2000 view sysobjects is still available in later versions for backward compatibility reasons.

Upvotes: 1

Related Questions