• Utente di eliminazione di SQL Server non riuscito: "L'entità di database possiede uno schema nel database e non può essere eliminato. (Microsoft SQL Server, errore: 15138)"

    Se si tenta di eliminare un utente proprietario di uno schema, verrà visualizzato il seguente errore: Eliminazione non riuscita per l'utente 'my_user'.  (Microsoft.SqlServer.Smo) L'entità di database possiede uno schema nel database e non può essere eliminato. (Microsoft SQL Server, errore: 15138) Pertanto, per eliminare l'utente, è necessario trovare lo schema a cui è proprietario e trasferire la proprietà a un altro utente (o ruolo). Utilizzare questa query per trovare lo schema a cui appartiene l'utente:Use this query to find the schema the user belongs:   SELECT sc.name FROM sys.schemas sc WHERE sc.principal_id : USER_ID('utente_personale') Una volta trovato lo schema con la query precedente (ad esempio "db_datareader"), utilizzarlo per trasferire la…

  • SQL Server drop user failed: “The database principal owns a schema in the database, and cannot be dropped. (Microsoft SQL Server, Error: 15138)”

    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:   SELECT sc.name FROM sys.schemas sc WHERE sc.principal_id = USER_ID('my_user') Once you find the schema with the previous query (eg “db_datareader”), use it to transfer the ownership with this snippet:   ALTER AUTHORIZATION ON SCHEMA::db_datareader…