If you try to delete a user who owns a schema, you will receive the following error:
Drop failed for User ‘my_user’. (Microsoft.SqlServer.Smo)
The database principal owns a schema in the database, and cannot be dropped. (Microsoft SQL Server, Error: 15138)
Therefore, to delete the user, you have to find the schema to which it owns, and transfer the ownership to another user (or role).
Use this query to find the schema the user belongs:
sc.principal_id = USER_ID(
Once you find the schema with the previous query (eg “db_datareader”), use it to transfer the ownership with this snippet: