SQL Object Ownership script


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


Comments

Please login to comment