There was a problem loading the comments.

SQL Object Ownership script

Support Portal  »  Knowledgebase  »  Viewing Article

  Print
DECLARE @objname nvarchar(517),
@DynSQL nvarchar(4000)

DECLARE obj_cursor CURSOR FOR
SELECT name FROM sysobjects
WHERE Uid <> 1

OPEN obj_cursor
FETCH NEXT FROM obj_cursor
INTO @objname

WHILE @@FETCH_STATUS = 0
BEGIN
PRINT 'Setting ownership on ' + @objname

SET @DynSQL = 'sp_changeobjectowner ''CHANGETHISFORYOURUSERNAME.' + convert(varchar, @objname) + ''' , ''dbo'''

--PRINT @DynSQL

EXECUTE sp_executesql @DynSQL

FETCH NEXT FROM obj_cursor
INTO @objname

END

CLOSE obj_cursor
DEALLOCATE obj_cursor


Share via

Related Articles

© Hosting UK