How do you change the table_schema when the current table_schema is null?









up vote
0
down vote

favorite












I somehow managed to create a table in a database with a null table schema.
I can't query the table since it has no owner, and altering the table doesn't work for the same reason.



I would alter the table using:



ALTER SCHEMA null TRANSFER dbo.SubscriptionAnswerMR


But that doesn't work.



The information_schema.tables looks like this:



TABLE_CATALOG TABLE_SCHEMA TABLE_NAME TABLE_TYPE
q_Profiles NULL SubscriptionAnswerMR BASE TABLE


So my question is: How do I change q_Profiles' table_schema?



SQL Server 2000 (edit)
Microsoft SQL Server Management Studio 2008R2










share|improve this question























  • What does sysobjects say?
    – Aaron Bertrand
    May 14 '12 at 19:18















up vote
0
down vote

favorite












I somehow managed to create a table in a database with a null table schema.
I can't query the table since it has no owner, and altering the table doesn't work for the same reason.



I would alter the table using:



ALTER SCHEMA null TRANSFER dbo.SubscriptionAnswerMR


But that doesn't work.



The information_schema.tables looks like this:



TABLE_CATALOG TABLE_SCHEMA TABLE_NAME TABLE_TYPE
q_Profiles NULL SubscriptionAnswerMR BASE TABLE


So my question is: How do I change q_Profiles' table_schema?



SQL Server 2000 (edit)
Microsoft SQL Server Management Studio 2008R2










share|improve this question























  • What does sysobjects say?
    – Aaron Bertrand
    May 14 '12 at 19:18













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I somehow managed to create a table in a database with a null table schema.
I can't query the table since it has no owner, and altering the table doesn't work for the same reason.



I would alter the table using:



ALTER SCHEMA null TRANSFER dbo.SubscriptionAnswerMR


But that doesn't work.



The information_schema.tables looks like this:



TABLE_CATALOG TABLE_SCHEMA TABLE_NAME TABLE_TYPE
q_Profiles NULL SubscriptionAnswerMR BASE TABLE


So my question is: How do I change q_Profiles' table_schema?



SQL Server 2000 (edit)
Microsoft SQL Server Management Studio 2008R2










share|improve this question















I somehow managed to create a table in a database with a null table schema.
I can't query the table since it has no owner, and altering the table doesn't work for the same reason.



I would alter the table using:



ALTER SCHEMA null TRANSFER dbo.SubscriptionAnswerMR


But that doesn't work.



The information_schema.tables looks like this:



TABLE_CATALOG TABLE_SCHEMA TABLE_NAME TABLE_TYPE
q_Profiles NULL SubscriptionAnswerMR BASE TABLE


So my question is: How do I change q_Profiles' table_schema?



SQL Server 2000 (edit)
Microsoft SQL Server Management Studio 2008R2







sql-server sql-server-2000






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 14 '12 at 19:24









Aaron Bertrand

206k27361403




206k27361403










asked May 14 '12 at 17:32









Matt R

1,52742342




1,52742342











  • What does sysobjects say?
    – Aaron Bertrand
    May 14 '12 at 19:18

















  • What does sysobjects say?
    – Aaron Bertrand
    May 14 '12 at 19:18
















What does sysobjects say?
– Aaron Bertrand
May 14 '12 at 19:18





What does sysobjects say?
– Aaron Bertrand
May 14 '12 at 19:18













2 Answers
2






active

oldest

votes

















up vote
2
down vote



accepted










You should be able to verify that your table is fine by seeing the result of the following query:



SELECT u.name
FROM q_Profiles..sysobjects AS o
INNER JOIN q_Profiles..sysusers AS u
ON o.uid = u.uid
WHERE o.name = 'SubscriptionAnswerMR';


This should be dbo unless someone explicitly created them with a different owner or used sp_changeobjectowner. Which you can use if you find that sysobjects also has the wrong answer:



EXEC sp_changeobjectowner 'SubscriptionAnswerMR', 'dbo';


ALTER SCHEMA is not valid here because it was introduced in SQL Server 2005. Though it would be useful for you to describe what "doesn't work" means.



INFORMATION_SCHEMA is a horribly unreliable set of views as @Pondlife points out. Also see the following, which doesn't help you much in SQL Server 2000, but should help going forward:



  • The case against INFORMATION_SCHEMA views

Also as a side note you seem to be confused about tables and database. TABLE_CATALOG is the database, not the table.






share|improve this answer





























    up vote
    1
    down vote













    Did you note this comment in the documentation?




    Do not use INFORMATION_SCHEMA views to determine the schema of an
    object. The only reliable way to find the schema of a object is to
    query the sys.objects catalog view or use the OBJECT_SCHEMA_NAME
    function.







    share|improve this answer




















    • Agree 100%. Except OBJECT_SCHEMA_NAME() is not valid in SQL Server 2000, nor is sysobjects. Your documentation is too new! :-)
      – Aaron Bertrand
      May 14 '12 at 19:21











    • Absolutely right, although since the OP tagged his question as SQL 2008 (since updated) it's not surprising that I referred him to that documentation :-)
      – Pondlife
      May 14 '12 at 19:40










    • Ah, I missed the tag edit, sorry. :-)
      – Aaron Bertrand
      May 14 '12 at 19:41










    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',
    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%2f10588278%2fhow-do-you-change-the-table-schema-when-the-current-table-schema-is-null%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    You should be able to verify that your table is fine by seeing the result of the following query:



    SELECT u.name
    FROM q_Profiles..sysobjects AS o
    INNER JOIN q_Profiles..sysusers AS u
    ON o.uid = u.uid
    WHERE o.name = 'SubscriptionAnswerMR';


    This should be dbo unless someone explicitly created them with a different owner or used sp_changeobjectowner. Which you can use if you find that sysobjects also has the wrong answer:



    EXEC sp_changeobjectowner 'SubscriptionAnswerMR', 'dbo';


    ALTER SCHEMA is not valid here because it was introduced in SQL Server 2005. Though it would be useful for you to describe what "doesn't work" means.



    INFORMATION_SCHEMA is a horribly unreliable set of views as @Pondlife points out. Also see the following, which doesn't help you much in SQL Server 2000, but should help going forward:



    • The case against INFORMATION_SCHEMA views

    Also as a side note you seem to be confused about tables and database. TABLE_CATALOG is the database, not the table.






    share|improve this answer


























      up vote
      2
      down vote



      accepted










      You should be able to verify that your table is fine by seeing the result of the following query:



      SELECT u.name
      FROM q_Profiles..sysobjects AS o
      INNER JOIN q_Profiles..sysusers AS u
      ON o.uid = u.uid
      WHERE o.name = 'SubscriptionAnswerMR';


      This should be dbo unless someone explicitly created them with a different owner or used sp_changeobjectowner. Which you can use if you find that sysobjects also has the wrong answer:



      EXEC sp_changeobjectowner 'SubscriptionAnswerMR', 'dbo';


      ALTER SCHEMA is not valid here because it was introduced in SQL Server 2005. Though it would be useful for you to describe what "doesn't work" means.



      INFORMATION_SCHEMA is a horribly unreliable set of views as @Pondlife points out. Also see the following, which doesn't help you much in SQL Server 2000, but should help going forward:



      • The case against INFORMATION_SCHEMA views

      Also as a side note you seem to be confused about tables and database. TABLE_CATALOG is the database, not the table.






      share|improve this answer
























        up vote
        2
        down vote



        accepted







        up vote
        2
        down vote



        accepted






        You should be able to verify that your table is fine by seeing the result of the following query:



        SELECT u.name
        FROM q_Profiles..sysobjects AS o
        INNER JOIN q_Profiles..sysusers AS u
        ON o.uid = u.uid
        WHERE o.name = 'SubscriptionAnswerMR';


        This should be dbo unless someone explicitly created them with a different owner or used sp_changeobjectowner. Which you can use if you find that sysobjects also has the wrong answer:



        EXEC sp_changeobjectowner 'SubscriptionAnswerMR', 'dbo';


        ALTER SCHEMA is not valid here because it was introduced in SQL Server 2005. Though it would be useful for you to describe what "doesn't work" means.



        INFORMATION_SCHEMA is a horribly unreliable set of views as @Pondlife points out. Also see the following, which doesn't help you much in SQL Server 2000, but should help going forward:



        • The case against INFORMATION_SCHEMA views

        Also as a side note you seem to be confused about tables and database. TABLE_CATALOG is the database, not the table.






        share|improve this answer














        You should be able to verify that your table is fine by seeing the result of the following query:



        SELECT u.name
        FROM q_Profiles..sysobjects AS o
        INNER JOIN q_Profiles..sysusers AS u
        ON o.uid = u.uid
        WHERE o.name = 'SubscriptionAnswerMR';


        This should be dbo unless someone explicitly created them with a different owner or used sp_changeobjectowner. Which you can use if you find that sysobjects also has the wrong answer:



        EXEC sp_changeobjectowner 'SubscriptionAnswerMR', 'dbo';


        ALTER SCHEMA is not valid here because it was introduced in SQL Server 2005. Though it would be useful for you to describe what "doesn't work" means.



        INFORMATION_SCHEMA is a horribly unreliable set of views as @Pondlife points out. Also see the following, which doesn't help you much in SQL Server 2000, but should help going forward:



        • The case against INFORMATION_SCHEMA views

        Also as a side note you seem to be confused about tables and database. TABLE_CATALOG is the database, not the table.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 11 at 14:11

























        answered May 14 '12 at 19:21









        Aaron Bertrand

        206k27361403




        206k27361403






















            up vote
            1
            down vote













            Did you note this comment in the documentation?




            Do not use INFORMATION_SCHEMA views to determine the schema of an
            object. The only reliable way to find the schema of a object is to
            query the sys.objects catalog view or use the OBJECT_SCHEMA_NAME
            function.







            share|improve this answer




















            • Agree 100%. Except OBJECT_SCHEMA_NAME() is not valid in SQL Server 2000, nor is sysobjects. Your documentation is too new! :-)
              – Aaron Bertrand
              May 14 '12 at 19:21











            • Absolutely right, although since the OP tagged his question as SQL 2008 (since updated) it's not surprising that I referred him to that documentation :-)
              – Pondlife
              May 14 '12 at 19:40










            • Ah, I missed the tag edit, sorry. :-)
              – Aaron Bertrand
              May 14 '12 at 19:41














            up vote
            1
            down vote













            Did you note this comment in the documentation?




            Do not use INFORMATION_SCHEMA views to determine the schema of an
            object. The only reliable way to find the schema of a object is to
            query the sys.objects catalog view or use the OBJECT_SCHEMA_NAME
            function.







            share|improve this answer




















            • Agree 100%. Except OBJECT_SCHEMA_NAME() is not valid in SQL Server 2000, nor is sysobjects. Your documentation is too new! :-)
              – Aaron Bertrand
              May 14 '12 at 19:21











            • Absolutely right, although since the OP tagged his question as SQL 2008 (since updated) it's not surprising that I referred him to that documentation :-)
              – Pondlife
              May 14 '12 at 19:40










            • Ah, I missed the tag edit, sorry. :-)
              – Aaron Bertrand
              May 14 '12 at 19:41












            up vote
            1
            down vote










            up vote
            1
            down vote









            Did you note this comment in the documentation?




            Do not use INFORMATION_SCHEMA views to determine the schema of an
            object. The only reliable way to find the schema of a object is to
            query the sys.objects catalog view or use the OBJECT_SCHEMA_NAME
            function.







            share|improve this answer












            Did you note this comment in the documentation?




            Do not use INFORMATION_SCHEMA views to determine the schema of an
            object. The only reliable way to find the schema of a object is to
            query the sys.objects catalog view or use the OBJECT_SCHEMA_NAME
            function.








            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered May 14 '12 at 17:46









            Pondlife

            14.1k52948




            14.1k52948











            • Agree 100%. Except OBJECT_SCHEMA_NAME() is not valid in SQL Server 2000, nor is sysobjects. Your documentation is too new! :-)
              – Aaron Bertrand
              May 14 '12 at 19:21











            • Absolutely right, although since the OP tagged his question as SQL 2008 (since updated) it's not surprising that I referred him to that documentation :-)
              – Pondlife
              May 14 '12 at 19:40










            • Ah, I missed the tag edit, sorry. :-)
              – Aaron Bertrand
              May 14 '12 at 19:41
















            • Agree 100%. Except OBJECT_SCHEMA_NAME() is not valid in SQL Server 2000, nor is sysobjects. Your documentation is too new! :-)
              – Aaron Bertrand
              May 14 '12 at 19:21











            • Absolutely right, although since the OP tagged his question as SQL 2008 (since updated) it's not surprising that I referred him to that documentation :-)
              – Pondlife
              May 14 '12 at 19:40










            • Ah, I missed the tag edit, sorry. :-)
              – Aaron Bertrand
              May 14 '12 at 19:41















            Agree 100%. Except OBJECT_SCHEMA_NAME() is not valid in SQL Server 2000, nor is sysobjects. Your documentation is too new! :-)
            – Aaron Bertrand
            May 14 '12 at 19:21





            Agree 100%. Except OBJECT_SCHEMA_NAME() is not valid in SQL Server 2000, nor is sysobjects. Your documentation is too new! :-)
            – Aaron Bertrand
            May 14 '12 at 19:21













            Absolutely right, although since the OP tagged his question as SQL 2008 (since updated) it's not surprising that I referred him to that documentation :-)
            – Pondlife
            May 14 '12 at 19:40




            Absolutely right, although since the OP tagged his question as SQL 2008 (since updated) it's not surprising that I referred him to that documentation :-)
            – Pondlife
            May 14 '12 at 19:40












            Ah, I missed the tag edit, sorry. :-)
            – Aaron Bertrand
            May 14 '12 at 19:41




            Ah, I missed the tag edit, sorry. :-)
            – Aaron Bertrand
            May 14 '12 at 19:41

















            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2f10588278%2fhow-do-you-change-the-table-schema-when-the-current-table-schema-is-null%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







            這個網誌中的熱門文章

            What does pagestruct do in Eviews?

            Dutch intervention in Lombok and Karangasem

            Channel Islands