Quantcast
Viewing all articles
Browse latest Browse all 3587

Re: MDA Tables:  Why is the owner_name omitted in most of the MDA tables?

did not find elegant approach, just some workarounds, which mostly already were mentioned in initial message

 

 

1) select user_name(object_owner_id(1)) refers only to the users in current database

so alternatively would be nice to have second argument for user_name

 

 

2) it is possible to create function like this

 

 

create function owner_name(@objid int, @dbid int = null)

returns longsysname

as

begin

    declare @n longsysname

    declare @sql varchar(8000)

    set @objid = isnull(@objid,db_id())

    set @sql = 'select @n=name from ' + db_name(@dbid) + '..sysusers where uid=' + convert(varchar,object_owner_id(@objid, @dbid))

    execute (@sql)

    return @n

end

 

 

but this is actually what you said "create a dynamic query for each and every row"

 

 

3) if I correctly understand your idea about look up table, you meant to create look up table for object-to-user,.. suppose object_owner_id might bring some new life to this idea, just create look up table/view for sysusers

 

 

create view allsysusers

as

select db_id('pubs2') dbid , uid, name from pubs2..sysusers

union all

select db_id('pubs3') dbid , uid, name from pubs3..sysusers

 

 

 

select u.name, o.ObjectName

from monOpenObjectActivity o

join allsysusers u on object_owner_id(o.ObjectID, o.DBID) = u.uid and o.DBID = u.dbid


Viewing all articles
Browse latest Browse all 3587

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>