Some websites use virtual hosts. If SQL-server is used to import data.
By default, database users are the users you log on to, rather than DBO. Sometimes they are different from local users.
-- Function Description: Modify database owner objects in batches.
-- Author: Unknown
-- Usage: exec changeobjectowner 'nmkspro', 'dbo'
-- Change the object of all nmkspro owners to DBO
-- After running successfully, the system prompts: "NOTE: changing any part of the object name may damage the script and stored procedure. "
Create procedure DBO. changeobjectowner
@ Oldowner as nvarchar (128), -- original parameter owner
@ Newowner as nvarchar (128) -- New Parameter owner
As
Declare @ name as nvarchar (128)
Declare @ owner as nvarchar (128)
Declare @ ownername as nvarchar (128)
Declare curobject cursor
Select 'name' = Name,
'Owner' = user_name (UID)
From sysobjects
Where user_name (UID) = @ oldowner
Order by name
Open curobject
Fetch next from curobject into @ name, @ owner
While (@ fetch_status = 0)
Begin
If @ owner = @ oldowner
Begin
Set @ ownername = @ oldowner + '.' + rtrim (@ name)
Exec sp_changeobjectowner @ ownername, @ newowner
End
Fetch next from curobject into @ name, @ owner
End
Close curobject
Deallocate curobject
Go
Batch modification:
Exec sp_msforeachtable 'exec sp_changeobjectowner ''? '', ''Dbo '''
Single modification:
Exec sp_changeobjectowner 'name of the table to be changed ', 'dbo'
Method 1: Click the table-design-properties-to change the owner. This method is applicable when the number of tables is small.
Method 2: Execute the script directly, log on to the database with a system account or a super user, and then execute the following statement:
Sp_configure 'Allow updates', '1'
Go
Reconfigure with override
Go
Update sysobjects set UID = 1 where uid <> 1 -- you can modify it based on the conditions and switch between multiple users.
Go
Sp_configure 'Allow updates', '0'
Go
Reconfigure with override