August 28, 2008 at 7:07 pm
Can anyone please help me find a script that will give me a list of all the usernames and roles for all databases in SQL 2000
Thanks in advance.
August 28, 2008 at 8:50 pm
Try this:
declare @sql varchar(8000)
Declare @DB_Objects varchar(8000)
Select @DB_Objects = ' name COLLATE DATABASE_DEFAULT as [Name], uid, status, sid, createdate, updatedate
From %D%.dbo.sysusers
'
Select @sql = 'SELECT * FROM
(Select '+Cast(dbid as varchar(9))+' as DBID, ''master'' as DBName, '
+ Replace(@DB_objects, '%D%', [name])
From master.dbo.sysdatabases
Where [name] = 'master'
Select @sql = @sql + 'UNION ALL Select '+Cast(dbid as varchar(9))+', '''+[name]+''', '
+ Replace(@DB_objects, '%D%', [name])
From master.dbo.sysdatabases
Where [name] != 'master'
print @sql
EXEC (@sql)
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
August 28, 2008 at 10:15 pm
Ran it in SQL 2000, got the following error:
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'MAX'.
Server: Msg 137, Level 15, State 1, Line 6
Must declare the variable '@DB_Objects'.
Server: Msg 137, Level 15, State 1, Line 8
Must declare the variable '@DB_objects'.
Server: Msg 137, Level 15, State 1, Line 12
Must declare the variable '@sql'.
Server: Msg 137, Level 15, State 1, Line 17
Must declare the variable '@sql'.
Server: Msg 137, Level 15, State 1, Line 19
Must declare the variable '@sql'.
Server: Msg 137, Level 15, State 1, Line 20
Must declare the variable '@sql'.
Please advise.
Thank you.
August 28, 2008 at 10:33 pm
OK, this should correct thos errors:
declare @sql varchar(8000)
Declare @DB_Objects varchar(8000)
Select @DB_Objects = ' name COLLATE DATABASE_DEFAULT as [Name], uid, status, sid, createdate, updatedate
From %D%.dbo.sysusers
'
Select @sql = 'SELECT * FROM
(Select '+Cast(dbid as varchar(9))+' as DBID, ''master'' as DBName, '
+ Replace(@DB_objects, '%D%', [name])
From master.dbo.sysdatabases
Where [name] = 'master'
Select @sql = @sql + 'UNION ALL Select '+Cast(dbid as varchar(9))+', '''+[name]+''', '
+ Replace(@DB_objects, '%D%', [name])
From master.dbo.sysdatabases
Where [name] != 'master'
print @sql
EXEC (@sql)
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
August 28, 2008 at 10:54 pm
Now getting the following error:
Server: Msg 207, Level 16, State 3, Line 1
Invalid column name 'name'.
Server: Msg 207, Level 16, State 1, Line 1
Invalid column name 'uid'.
Server: Msg 207, Level 16, State 1, Line 1
Invalid column name 'status'.
Server: Msg 207, Level 16, State 1, Line 1
Invalid column name 'sid'.
Server: Msg 207, Level 16, State 1, Line 1
Invalid column name 'createdate'.
Server: Msg 207, Level 16, State 1, Line 1
Invalid column name 'updatedate'.
Thank you for your help....look forward to hearing back form you
August 29, 2008 at 8:59 am
I have tested this my last posted query on one of the few SQL 2000 servers that I still have access to and it worked fine, and I can think of no reason why you should be getting those errors.
Please post the PRINT command output from your server and I will try that here.
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
August 29, 2008 at 5:51 pm
Due to security reasons I cannot list the print statement here as it lists all the databases in the sql server. Plus how is that statement going to help you if you donot have access to the same server that I am running it on.
Your varchar(8000) is not long enough to list all the dbs in my server.
Your script does not work, its ok dont worry about it. I was able to get another script from Expert Exchange.
Thanks for your help.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply