SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Script to find username and corresponding loginname for all user DB


Script to find username and corresponding loginname for all user DB

Author
Message
Shashank Srivastava
Shashank Srivastava
SSC Veteran
SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)

Group: General Forum Members
Points: 232 Visits: 210
Comments posted to this topic are about the item Script to find username and corresponding loginname for all user DB

Regards
Shashank Srivastava
MCITP - SQL SERVER 2008
INDIA
Follow me @ http://shashanksrivastavasqldba.blogspot.com/
spectrumplus1
spectrumplus1
Grasshopper
Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)

Group: General Forum Members
Points: 16 Visits: 1
we can check the username in oracle by below command


show user;






https:www.spectrumplus.in
ken.trock
ken.trock
SSCrazy
SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)

Group: General Forum Members
Points: 2488 Visits: 1736
Nice use of MS_ForEachDB here. We don't use it much here because it's undocumented and can be a little picky with syntax. We use this type of construct to loop DBs:


DECLARE @databases TABLE(dbName VARCHAR(100))
DECLARE @CurrentDB VARCHAR(100), @SQL NVARCHAR(max)

--Exclude system DBs
INSERT @databases SELECT name from sys.databases WHERE database_id > 4

WHILE EXISTS (SELECT TOP 1 dbName FROM @databases)
BEGIN
SET @CurrentDB = (SELECT TOP 1 dbName FROM @databases)
SET @SQL = 'Use ' + @CurrentDB + '; <Take some action>'
--PRINT @sql
EXEC sp_executesql @SQL
DELETE @databases WHERE dbName = @CurrentDB
END



Ken
HildaJ
HildaJ
SSCrazy
SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)

Group: General Forum Members
Points: 2553 Visits: 574
Very nice script, I was in fact looking for a way to pull this information together. I found a few scripts that gave me too much and some too little. Thanks for doing the heavy work for us. I'm finding this script very handy.
HildaJ
HildaJ
SSCrazy
SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)

Group: General Forum Members
Points: 2553 Visits: 574
Shaz I made a small change to your script to work with my databases. I have a couple that have a space in the file name. No major change, just added the few brakets to the ? below.

set @Command= 'if not exists (select * from #systemdbs where name = ''[?]'') begin '+char(13)+
+'use [?] ; insert #dbusersbuffer exec sp_helpuser'+char(13)
+'insert #dbusers select ''?'', * from #dbusersbuffer'+char(13)
+'truncate table #dbusersbuffer'+char(13)
+'end'
Lee Linares
Lee Linares
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1421 Visits: 1539
Nice script. Thanks for taking the time to share. I ran into one problem though. I get this error:
Msg 213, Level 16, State 7, Procedure sp_helpuser, Line 250
Insert Error: Column name or number of supplied values does not match table definition.

The reason is that sp_helpuser will return 2 result sets if aliases exist in any database.

Thanks again,

Lee
Shashank Srivastava
Shashank Srivastava
SSC Veteran
SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)

Group: General Forum Members
Points: 232 Visits: 210
Thanks.

Regards
Shashank Srivastava
MCITP - SQL SERVER 2008
INDIA
Follow me @ http://shashanksrivastavasqldba.blogspot.com/
Shashank Srivastava
Shashank Srivastava
SSC Veteran
SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)

Group: General Forum Members
Points: 232 Visits: 210
Happy to help you. Thanks

Regards
Shashank Srivastava
MCITP - SQL SERVER 2008
INDIA
Follow me @ http://shashanksrivastavasqldba.blogspot.com/
Shashank Srivastava
Shashank Srivastava
SSC Veteran
SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)

Group: General Forum Members
Points: 232 Visits: 210
Thank you for the modification . Yes we need to make those changes to include databases that have spaces.

Regards
Shashank Srivastava
MCITP - SQL SERVER 2008
INDIA
Follow me @ http://shashanksrivastavasqldba.blogspot.com/
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum







































































































































































SQLServerCentral


Search