I am creating a stored procedure to generate the sp_addrolemember syntax, since SQL 2005 does not script role members. The stored procedure is named sp_ so it can be executed from any database. However, any reference to a view beginning with sys. only gets executed in the master database and not the current database. Why? Try this code for a test. Use Master GO Create Procedure sp_test as Begin Select g.name, u.name From sys.database_principals u, sys.database_principals g, sys.database_role_members mWhere g.principal_id = m.role_principal_id And u.principal_id = m.member_principal_id And u.name <> 'dbo'Order by g.name, u.nameEnd -- Run sp_test from a database containing fixed database role members. The select only runs against master and not the current DB.