Solved

adding database name in sp_helpuser

Posted on 2010-09-07
5
734 Views
Last Modified: 2012-05-10
is it possible to add the database name in the below code, so i can know which databases have the users with the role backupoperator

thanks
create table #DBO  (GName varchar(80),GID int,User_id_DB varchar(80),uid smallint)

exec sp_msforeachdb 'use [?] insert into #DBO exec sp_helpuser db_backupoperator'  

select * from #DBO where User_id_DB <> 'dbo'

drop table #DBO

Open in new window

0
Comment
Question by:anushahanna
  • 2
  • 2
5 Comments
 
LVL 60

Accepted Solution

by:
chapmandew earned 480 total points
ID: 33619761
create table #DBO  (GName varchar(80),GID int,User_id_DB varchar(80),uid smallint, dbname sysname)
exec sp_msforeachdb 'use [?] insert into #DBO exec sp_helpuser db_backupoperator update #DBO set dbname = ''?'' where dbname is null'  
select * from #DBO where User_id_DB <> 'dbo'
drop table #DBO
0
 
LVL 65

Assisted Solution

by:rockiroads
rockiroads earned 20 total points
ID: 33619775
db_name() is a function in t-sql that should get current database
0
 
LVL 60

Assisted Solution

by:chapmandew
chapmandew earned 480 total points
ID: 33619804
quick fix...make sure you always list the field names


create table #DBO  (GName varchar(80),GID int,User_id_DB varchar(80),uid smallint, dbname sysname)
exec sp_msforeachdb 'use [?] insert into #DBO(gname, gid, user_id, uid) exec sp_helpuser db_backupoperator update #DBO set dbname = ''?'' where dbname is null'  
select * from #DBO where User_id_DB <> 'dbo'
drop table #DBO
0
 
LVL 6

Author Comment

by:anushahanna
ID: 33619991
Thanks Tim.
0
 
LVL 6

Author Comment

by:anushahanna
ID: 33619997
rockiroads, db_name() does not quiet work right inside the sp.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now