Your Webhosting Questions
Answered by the Webhosting Experts
Tags
...
...

Change ownership of a table through MS SQL

DECLARE @old sysname, @new sysname, @sql varchar(1000) SELECT @old = 'oldOwner_CHANGE_THIS' , @new = 'dbo' , @sql = ' IF EXISTS (SELECT NULL FROM INFORMATION_SCHEMA.TABLES WHERE QUOTENAME(TABLE_SCHEMA)+''.''+QUOTENAME(TABLE_NAME) = ''?'' AND TABLE_SCHEMA = ''' + @old + ''' ) EXECUTE sp_changeobjectowner ''?'', ''' + @new + '''' EXECUTE sp_MSforeachtable @sql

—– The same can be done to stored procedures: —–

DECLARE @oldOwner sysname, @newOwner sysname SELECT @oldOwner = 'oldOwner_CHANGE_THIS' , @newOwner = 'dbo' select 'EXECUTE sp_changeobjectowner '''+QUOTENAME(a.SPECIFIC_SCHEMA)+'.'+QUOTENAME(a.ROUTINE_NAME)+''','''+@newOwner+'''' from INFORMATION_SCHEMA.ROUTINES a where a.ROUTINE_TYPE = 'PROCEDURE' AND a.SPECIFIC_SCHEMA = @oldOwner AND OBJECTPROPERTY(OBJECT_ID(QUOTENAME(a.SPECIFIC_SCHEMA)+'.'+QUOTENAME(a.ROUTINE_NAME)), 'IsMSShipped') = 0 DECLARE @old sysname, @new sysname, @sql varchar(1000) SELECT @old = 'oldOwner' , @new = 'dbo' , @sql = ' IF EXISTS (SELECT NULL FROM information_schema.routines WHERE QUOTENAME(ROUTINE_SCHEMA)+''.''+QUOTENAME(ROUTINE_NAME) = ''?'' AND ROUTINE_SCHEMA = ''' + @old + ''' ) EXECUTE sp_changeobjectowner ''?'', ''' + @new + '''' EXECUTE sp_MSforeachtable @sql

Need More Personalized Help?

If you have any further issues, questions, or would like some assistance checking on this or anything else, please reach out to us from your my.hivelocity.net account and provide your server credentials within the encrypted field for the best possible security and support.

If you are unable to reach your my.hivelocity.net account or if you are on the go, please reach out from your valid my.hivelocity.net account email to us here at: support@hivelocity.net. We are also available to you through our phone and live chat system 24/7/365.

Tags +
...