1

I want to write a query which will give all the databases on the server which accessability to the user (read or more access).

Thanks, Omkar.

1 Answer 1

7

How about

SELECT name, HAS_DBACCESS(name) FROM sys.databases;
5
  • It also list system databases like master, tempdb. What to do if I dont want it ? Nov 18, 2013 at 13:18
  • @Upendra you add a WHERE clause, like name not in (N'master', N'tempdb', ...) Nov 18, 2013 at 14:01
  • Yes, I can add filter condition like you mentioned, but I want any column from which I can identify like these are system databases. Nov 19, 2013 at 4:19
  • @UpendraChaudhari sorry, there is no such column. You'd think there might be something in sys.databases, DATABASEPROPERTY (deprecated) or DATABASEPROPERTYEX (surely on the way to being deprecated) but no such luck. You can exclude the four common ones by name, or using WHERE database_id > 4 - however this doesn't handle things like ReportServerTempDB, the new SSIS catalog, etc. Nov 19, 2013 at 5:41
  • @AaronBertrand: OK thanks for your reply and valuable time. I will filter like that Nov 19, 2013 at 6:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.