Sunday, February 19, 2012

DBO Query

Is there a query that can be executed to check if the currently logged in
user has dbo access to the current database?
I need to know this prior to adding tables.
Thanks in advance.
Hi Isaac,
Yes, use is_member() like in
if is_member('db_owner') = 1
-- do something
You may also want to take a look at is_srvrolemember.
Hope this helps,
Ben Nevarez
"Isaac Alexander" wrote:

> Is there a query that can be executed to check if the currently logged in
> user has dbo access to the current database?
> I need to know this prior to adding tables.
> Thanks in advance.
>
>
|||To get the logged in user a member of the fixed database role, look up
IS_MEMBER() function. If you want to know if a particular user belongs to a
particular database role, try the check:
IF EXISTS ( SELECT *
FROM sysmembers s1
JOIN sysusers s2 ON s2.uid = s1.memberuid
JOIN sysusers s3 ON s3.uid = s1.groupuid AND s3.issqlrole = 1
WHERE s3.name = @.role AND s2.name = @.user )
Anith
|||> if is_member('db_owner') = 1
> -- do something
That worked perfectly. Thanks.

No comments:

Post a Comment