How to drop a SQL Server user with db owner privilege












8















I need to drop a user with dbowner schema from a SQL Server database. I cannot drop it as it is since I get this error message




Drop failed for User 'network service'. (Microsoft.SqlServer.Smo)



The database principal owns a schema in the database, and cannot be dropped. (Microsoft SQL Server, Error: 15138)




When I try to uncheck the schema owned by this user to remove db owner it does nothing. My question is how I can drop this user or edit its name from 'network service' to 'NT AUTHORITYNETWORK SERVICE'










share|improve this question





























    8















    I need to drop a user with dbowner schema from a SQL Server database. I cannot drop it as it is since I get this error message




    Drop failed for User 'network service'. (Microsoft.SqlServer.Smo)



    The database principal owns a schema in the database, and cannot be dropped. (Microsoft SQL Server, Error: 15138)




    When I try to uncheck the schema owned by this user to remove db owner it does nothing. My question is how I can drop this user or edit its name from 'network service' to 'NT AUTHORITYNETWORK SERVICE'










    share|improve this question



























      8












      8








      8








      I need to drop a user with dbowner schema from a SQL Server database. I cannot drop it as it is since I get this error message




      Drop failed for User 'network service'. (Microsoft.SqlServer.Smo)



      The database principal owns a schema in the database, and cannot be dropped. (Microsoft SQL Server, Error: 15138)




      When I try to uncheck the schema owned by this user to remove db owner it does nothing. My question is how I can drop this user or edit its name from 'network service' to 'NT AUTHORITYNETWORK SERVICE'










      share|improve this question
















      I need to drop a user with dbowner schema from a SQL Server database. I cannot drop it as it is since I get this error message




      Drop failed for User 'network service'. (Microsoft.SqlServer.Smo)



      The database principal owns a schema in the database, and cannot be dropped. (Microsoft SQL Server, Error: 15138)




      When I try to uncheck the schema owned by this user to remove db owner it does nothing. My question is how I can drop this user or edit its name from 'network service' to 'NT AUTHORITYNETWORK SERVICE'







      sql-server sql-manager






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 16 '16 at 14:32









      marc_s

      575k12811091256




      575k12811091256










      asked Feb 16 '16 at 13:50









      Sofia KhwajaSofia Khwaja

      4992716




      4992716
























          3 Answers
          3






          active

          oldest

          votes


















          8














          take a look at this:



          http://www.itorian.com/2012/12/the-database-principal-owns-schema-in.html



          It suggests that you need to add another owner first






          share|improve this answer































            7














            I had the same problem, i run two script then my problem is solved.



            try this:



            In this query you can get user schema as a result for AdventureWorks database



            USE AdventureWorks;
            SELECT s.name
            FROM sys.schemas s
            WHERE s.principal_id = USER_ID('your username');


            after take schema name you can alter authorization on schema like this:



            ALTER AUTHORIZATION ON SCHEMA::db_owner TO dbo;


            in this query db_owner schema name that get from first query.



            finally you can delete user without error.



            my source: SQL SERVER – Fix: Error: 15138






            share|improve this answer



















            • 1





              This option worked for me after trying the accepted answer first (which did not help; not sure why, they are very similar).

              – AcePL
              Aug 15 '18 at 15:43





















            -1














            ALTER AUTHORIZATION ON SCHEMA::[NT AUTHORITYSYSTEM] TO dbo





            share|improve this answer

























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f35434389%2fhow-to-drop-a-sql-server-user-with-db-owner-privilege%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              8














              take a look at this:



              http://www.itorian.com/2012/12/the-database-principal-owns-schema-in.html



              It suggests that you need to add another owner first






              share|improve this answer




























                8














                take a look at this:



                http://www.itorian.com/2012/12/the-database-principal-owns-schema-in.html



                It suggests that you need to add another owner first






                share|improve this answer


























                  8












                  8








                  8







                  take a look at this:



                  http://www.itorian.com/2012/12/the-database-principal-owns-schema-in.html



                  It suggests that you need to add another owner first






                  share|improve this answer













                  take a look at this:



                  http://www.itorian.com/2012/12/the-database-principal-owns-schema-in.html



                  It suggests that you need to add another owner first







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Feb 16 '16 at 14:07









                  Kevin MKevin M

                  20819




                  20819

























                      7














                      I had the same problem, i run two script then my problem is solved.



                      try this:



                      In this query you can get user schema as a result for AdventureWorks database



                      USE AdventureWorks;
                      SELECT s.name
                      FROM sys.schemas s
                      WHERE s.principal_id = USER_ID('your username');


                      after take schema name you can alter authorization on schema like this:



                      ALTER AUTHORIZATION ON SCHEMA::db_owner TO dbo;


                      in this query db_owner schema name that get from first query.



                      finally you can delete user without error.



                      my source: SQL SERVER – Fix: Error: 15138






                      share|improve this answer



















                      • 1





                        This option worked for me after trying the accepted answer first (which did not help; not sure why, they are very similar).

                        – AcePL
                        Aug 15 '18 at 15:43


















                      7














                      I had the same problem, i run two script then my problem is solved.



                      try this:



                      In this query you can get user schema as a result for AdventureWorks database



                      USE AdventureWorks;
                      SELECT s.name
                      FROM sys.schemas s
                      WHERE s.principal_id = USER_ID('your username');


                      after take schema name you can alter authorization on schema like this:



                      ALTER AUTHORIZATION ON SCHEMA::db_owner TO dbo;


                      in this query db_owner schema name that get from first query.



                      finally you can delete user without error.



                      my source: SQL SERVER – Fix: Error: 15138






                      share|improve this answer



















                      • 1





                        This option worked for me after trying the accepted answer first (which did not help; not sure why, they are very similar).

                        – AcePL
                        Aug 15 '18 at 15:43
















                      7












                      7








                      7







                      I had the same problem, i run two script then my problem is solved.



                      try this:



                      In this query you can get user schema as a result for AdventureWorks database



                      USE AdventureWorks;
                      SELECT s.name
                      FROM sys.schemas s
                      WHERE s.principal_id = USER_ID('your username');


                      after take schema name you can alter authorization on schema like this:



                      ALTER AUTHORIZATION ON SCHEMA::db_owner TO dbo;


                      in this query db_owner schema name that get from first query.



                      finally you can delete user without error.



                      my source: SQL SERVER – Fix: Error: 15138






                      share|improve this answer













                      I had the same problem, i run two script then my problem is solved.



                      try this:



                      In this query you can get user schema as a result for AdventureWorks database



                      USE AdventureWorks;
                      SELECT s.name
                      FROM sys.schemas s
                      WHERE s.principal_id = USER_ID('your username');


                      after take schema name you can alter authorization on schema like this:



                      ALTER AUTHORIZATION ON SCHEMA::db_owner TO dbo;


                      in this query db_owner schema name that get from first query.



                      finally you can delete user without error.



                      my source: SQL SERVER – Fix: Error: 15138







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered May 9 '18 at 9:36









                      Hasan FathiHasan Fathi

                      2,11412026




                      2,11412026








                      • 1





                        This option worked for me after trying the accepted answer first (which did not help; not sure why, they are very similar).

                        – AcePL
                        Aug 15 '18 at 15:43
















                      • 1





                        This option worked for me after trying the accepted answer first (which did not help; not sure why, they are very similar).

                        – AcePL
                        Aug 15 '18 at 15:43










                      1




                      1





                      This option worked for me after trying the accepted answer first (which did not help; not sure why, they are very similar).

                      – AcePL
                      Aug 15 '18 at 15:43







                      This option worked for me after trying the accepted answer first (which did not help; not sure why, they are very similar).

                      – AcePL
                      Aug 15 '18 at 15:43













                      -1














                      ALTER AUTHORIZATION ON SCHEMA::[NT AUTHORITYSYSTEM] TO dbo





                      share|improve this answer






























                        -1














                        ALTER AUTHORIZATION ON SCHEMA::[NT AUTHORITYSYSTEM] TO dbo





                        share|improve this answer




























                          -1












                          -1








                          -1







                          ALTER AUTHORIZATION ON SCHEMA::[NT AUTHORITYSYSTEM] TO dbo





                          share|improve this answer















                          ALTER AUTHORIZATION ON SCHEMA::[NT AUTHORITYSYSTEM] TO dbo






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Nov 25 '18 at 15:17









                          Larnu

                          17.3k41630




                          17.3k41630










                          answered Nov 25 '18 at 13:07









                          Joy BhattacharyaJoy Bhattacharya

                          1




                          1






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f35434389%2fhow-to-drop-a-sql-server-user-with-db-owner-privilege%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Contact image not getting when fetch all contact list from iPhone by CNContact

                              count number of partitions of a set with n elements into k subsets

                              A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks