March 14, 2006 at 6:40 am
Hi,
We are working on a web interface and we need to list all the database with particular login details.Is there a query from where i can geta list of database name authorised to a particular login.
Thanks and Regards
pavas
Pavas
Dream The Dream
Explore the World
Experince The Exhilaration
March 14, 2006 at 8:08 am
You will have to query sysusers for all the databases and use some unconventional features :
declare @cmd varchar(300)
select @cmd = 'select ''?'' as DB from [?].dbo.sysusers where isaliased = 0 and sid = ' + dbo.fn_varbintohexstr(suser_sid(suser_sname()))
--select @cmd
if object_id('tempdb..#t1') Is not null
drop table #t1
create table #t1 (databases varchar(128))
insert into #t1 (databases)
exec master..sp_MSforeachdb @cmd
select * from #t1
Cheers,
* Noel
March 14, 2006 at 11:17 pm
Hi,
The query looks good and fantastic but i m not able to understand this query,let me know where i can pass the user name of the database.
Pavas
Dream The Dream
Explore the World
Experince The Exhilaration
March 15, 2006 at 6:09 am
here's noeld's script witht he username pulled out as a parameter:in my example the username is 'hds'; i don't know how this will work for NT logins.
declare @cmd varchar(300)
declare @user varchar(30)
set @user='hds'
select @cmd = 'select ''?'' as DB from [?].dbo.sysusers where isaliased = 0 and sid = ' + dbo.fn_varbintohexstr(suser_sid(@user))
--select @cmd
if object_id('tempdb..#t1') Is not null
drop table #t1
create table #t1 (databases varchar(128))
insert into #t1 (databases)
exec master..sp_MSforeachdb @cmd
select * from #t1
Lowell
March 15, 2006 at 7:07 am
or
declare @cmd varchar(300)
declare @user varchar(30)
set @user='loginname'
select @cmd = 'SELECT DISTINCT ''?''
FROM master.dbo.syslogins l
inner join [?].dbo.sysusers o ON o.sid = l.sid
WHERE o.name = ''' + @user + '''
and o.hasdbaccess = 1'
create table #t1 (databases varchar(128))
insert into #t1 (databases)
exec master..sp_MSforeachdb @cmd
select * from #t1
drop table #t1
Far away is close at hand in the images of elsewhere.
Anon.
March 16, 2006 at 12:04 am
Thanks a lot both the queries are of great help
Pavas
Dream The Dream
Explore the World
Experince The Exhilaration
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply