use UeberpruefungBAG2024

-- Replace 'username' with the actual username
DECLARE @username NVARCHAR(128) = 'E-MEDIAT\uapvi';

-- Find schemas owned by the user
SELECT schema_name(schema_id) AS SchemaName
FROM sys.schemas
WHERE principal_id = USER_ID(@username);

-- Find objects owned by the user
SELECT 
    o.name AS ObjectName,
    o.type_desc AS ObjectType,
    s.name AS SchemaName
FROM 
    sys.objects o
JOIN 
    sys.schemas s ON o.schema_id = s.schema_id
WHERE 
    o.principal_id = USER_ID(@username);
GO

return

ALTER AUTHORIZATION ON SCHEMA::[db_owner] TO [dbo];
