views:

148

answers:

2

Hi,

I'd like to list all objects of a particular database in SQL Server 2005. I created a query as shown below:

select name, type_desc from sys.objects 
WHERE type in ( 'C', 'D', 'F', 'L', 'P', 'PK', 'RF', 'TR', 'UQ', 'V', 'X' ) 
union
select name, type_desc from sys.indexes
order by name

However, this query list all objects of ALL databases rather than a particular database.

My question is: Is there a way to query all objects of just a particular database? If yes, could you please show me how to do it?

A: 

Here's a better answer on an already asked and answered question:

http://stackoverflow.com/questions/1025022/find-an-object-in-mssql-cross-database

Sev
[name] does not contain the database name.
Cade Roux
Thanks for that, realized that a second after I posted. Post edited.
Sev
+2  A: 

Which database are you running this in? When I run it in a particular database, I don't get anything outside that database.

Cade Roux
Thanks. My mistake. I can get objects of a particular database.
titanium