How to drop a user attached to same schema with out dropping schema

  • As saw under schema properties below

    A database user can be dropped without dropping objects in a corresponding schema.

    My question here is when I am trying to drop a user ex 'testuser' which is tagged to a schema 'testuser' which has few objects (table and function) under that schema.

    When I am trying to drop the user am getting a below error msg.

    Msg 3729, Level 16, State 1, Procedure sp_revokedbaccess, Line 51

    Cannot drop schema 'testuser' because it is being referenced by object 'table'

    So i want to know the best method to drop the existing user 'testuser' and recreate it with different set of permissions.

    Thanks in advance!!

  • The user is also the owner of the schema. Change the owner of the schema, then you can drop the user.

    ALTER AUTHORIZATION ON SCHEMA::[Testuser] TO [dbo]

    GO

    For better, quicker answers, click on the following...
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • Thanks Mike for the reply...but one strange thing here in my scenario i canot change the schema to dbo coz the same objects exists on dbo schema as well as testuser.

    So will it be better

    1) to drop the schema then drop the user

    2) create the schema again and assign it new user created.

    or is there any other best way to do with out droping the schema?

    Cheers!!

  • It doesn't change the schema to dbo, it changes the owner of the schema to dbo, you'll still have both your schemas and your user will be free to be droped.

    You can reasign the schema to your user after you've changed the rights.

    You can also change the rights without droping the user though.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply