tags:

views:

529

answers:

2

I am retrieving the database list by executing the sp_databases stored proc. Is there any way I can exclude system databases from this list? I do not want to use the query SELECT name FROM dbo.sysdatabases where dbid > 6.

Thanks

+1  A: 

sp_databases takes no params.

The only thing you can do is use the INSERT EXEC pattern to insert into a table var and then select from the table var and exclude the dbs you want to exclude. Seems a bit messy, can you expand the context of this problem?

This works, but it is a little hacky:

create table #t (db_name varchar(255), db_size int, remarks text) 

insert #t 
exec sp_databases

select * from #t
where db_name not in ('master', 'model', 'tempdb', 'msdb')
Sam Saffron
This throws an exception with the following message: "EXECUTE cannot be used as a source when inserting into a table variable." pls help
Jay
I know these commands work with SqlServer 2005 and above. I'm using SqlServer 2008, but still I get this message
Jay
see the amended answer, changed it to a table var
Sam Saffron
Thanks a lot sambo. It worked!
Jay
A: 

Thanks Sambo.

I have a server's name/instance & I have to list the databases under that server. However, the 'SELECT...' query lists all the databases including those I don't have access to. But I want only those databases that I have access to. sp_databases is giving me the correct results, but along with sys Database names. I want to know how to filter those system database names that are being listed.

Jay