Technical Aspects in IT

Stand on the shoulders of giants – http://scholar.google.com

SQL Server Change Ownership

Posted by scmay on November 6, 2008

Bill Graziano  wrote a very useful script here

SELECT 'EXEC(''sp_changeobjectowner @objname = '''''+
  ltrim(u.name) + '.' + ltrim(s.name) + ''''''
  + ', @newowner = dbo'')'
FROM  sysobjects s,
      sysusers u
WHERE s.uid = u.uid
AND   u.name <> 'dbo'
AND   xtype in ('V', 'P', 'U')
AND   u.name not like 'INFORMATION%'
order by s.name
This query finds every view, stored procedure and user table in the database not owned by the dbo and converts ownership to the dbo.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>