SQL SERVER – List Databases Where User Has DB Access

Recently I got an email where my client asked if I know a way to know to which database the user has access. Well, it is pretty straightforward to know with the help of function HAS_DBACCESS. This is a very interesting function and it helps us to list databases where User Has DB Access. Let us see the example.

Here is the script which you can run to know to which database you have access. Now the function HAS_DBACCESS returns 1 if the user has access to the database, otherwise, it will return as 0. If you see value NULL, that means the database name passed to the function is invalid.

Has DB Access

SELECT name AS DatabaseName,
FROM sys.databases

Here are my few recent videos and I would like to know what is your feedback about them. Do not forget to subscribe SQL in Sixty Seconds series. I hope you appreciate learning about the Last 5 SQL in Sixty Seconds Video.

If you have any questions, you can always reach out to me on Twitter.

Reference: Pinal Dave (http://blog.SQLAuthority.com)

SQL Scripts, SQL Server, SQL Server Security
Previous Post
MySQL – Wait For Seconds Using SELECT SLEEP()
Next Post
SQL SERVER – Script to Estimate Compression

Related Posts

3 Comments. Leave new

Leave a ReplyCancel reply

Exit mobile version