Of course the exact purpose is change object owner, but the framework can be used for any repetitive operations.
-- Change the object owner from
-- PRODDTA to CRPDTA
USE PS_CRP
DECLARE @Object_Name AS varchar(60)
DECLARE curChange_Owner CURSOR READ_ONLY FORWARD_ONLY FOR
SELECT
sysusers.name + '.' + sysobjects.name
FROM
sysobjects , sysusers
WHERE
sysobjects.uid = sysusers.uid
AND
sysusers.name = 'PRODDTA'
AND
xtype = 'u'
OPEN curChange_Owner
FETCH NEXT FROM curChange_Owner INTO
@Object_Name
WHILE @@FETCH_STATUS = 0
BEGIN
EXEC sp_changeobjectowner @Object_Name, 'CRPDTA'
FETCH NEXT FROM curChange_Owner INTO
@Object_Name
END
CLOSE curChange_Owner
DEALLOCATE curChange_Owner
No comments:
Post a Comment