On a recent audit of a database I noticed that there were a lot of logins for a database that were not required. I set about removing the logins one by one, but soon hit the following error:
Error: 15138 The database principal owns a schema in the database, and cannot be dropped.
Well this threw me a bit, and I could not figure out what was going on and why, this one particular login could not be removed. As the message indicates, this account owns a schema on the DB. So I opened the user properties from SSMS and sure enough, the user in question owned three schemas: db_datareader, db_datawriter, db_owner. However, SSMS will not simply allow you to unselect the checkboxes here, so it is still not so easy to remove this link and allow the user to be deleted!
The schemas owned by the user can also be displayed by running the following query, within the context of the database under scrutiny:
SELECT s.name FROM sys.schemas s
WHERE s.principal_id = USER_ID('UserInQuestion'');
For a more complete picture of all schemas and users associated with the database:
SELECT *, USER_NAME(principal_id) as username
FROM sys.schemas;
In order to remove this user we have to first transfer ownership of these schemas to a different user. Typically this would be dbo. This has to be done once for each schema owned, using the ALTER AUTHORISATION ON SCHEMA command:
ALTER AUTHORISATION ON SCHEMA::db_datareader TO dbo
ALTER AUTHORISATION ON SCHEMA::db_datawriter TO dbo
ALTER AUTHORISATION ON SCHEMA::db_owner TO dbo
(note the double colon!)
Re-run the previous scripts to ensure that the user in question no longer owns any schemas. Now if we again try the delete again, this user will be removed successfully.
Showing posts with label database. Show all posts
Showing posts with label database. Show all posts
Wednesday, 5 March 2014
Friday, 27 September 2013
SSAS 2008: Clear Cache Command
When testing query perfornance on an SSAS database it's important to know if you are starting from a warm or clear cache. The simplest way to clear the cache is through an XMLA command, run from SSMS:
<ClearCache xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
<Object>
<DatabaseID>MyDatabase</DatabaseID>
</Object>
</ClearCache>
This clears the cache for the entire database. You can also clear the cache just for a specific cube:
<ClearCache xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
<Object>
<DatabaseID>MyDatabase</DatabaseID>
<CubeID>MyCube</CubeID>
</Object>
</ClearCache>
<ClearCache xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
<Object>
<DatabaseID>MyDatabase</DatabaseID>
</Object>
</ClearCache>
This clears the cache for the entire database. You can also clear the cache just for a specific cube:
<ClearCache xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
<Object>
<DatabaseID>MyDatabase</DatabaseID>
<CubeID>MyCube</CubeID>
</Object>
</ClearCache>
Labels:
2008 R2,
Analysis Services,
Cache,
Clear Cache,
Cube,
database,
performance,
query,
SQL 2012,
SSAS,
SSMS,
XMLA
Subscribe to:
Posts (Atom)