Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8495467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:34:56+00:00 2026-06-10T23:34:56+00:00

How do I get the schema name of the objects in the table sys.all_objects?

  • 0

How do I get the schema name of the objects in the table “sys.all_objects?”

Using the OBJECT_SCHEMA_NAME function returns “sys” when I know the schema is dbo…

select OBJECT_SCHEMA_NAME(o.schema_id),* from sys.all_objects o

I don’t want to use another view but I can join to other tables if necessary.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T23:34:58+00:00Added an answer on June 10, 2026 at 11:34 pm

    Are you talking about system objects such as sp_helptext? You can call sp_helptext and other system objects using multiple formats and these are translated for you (mostly for backward compatibility reasons):

    EXEC sp_helptext 'sp_helptext';
    EXEC dbo.sp_helptext 'sp_helptext';
    EXEC sys.sp_helptext 'sp_helptext';
    
    SELECT * FROM sysobjects;
    SELECT * FROM dbo.sysobjects;
    SELECT * FROM sys.sysobjects;    
    

    But the object can only belong to one schema. In this case it is sys even if it answers to dbo as well.

    If you have user objects that are showing up as sys, please let us know what they are. If you are just trying to track down user objects, perhaps you named something as dbo.foo that also exists under the sys schema. I might suggest sys.objects instead of sys.all_objects if you don’t want to return system objects.

    EDIT:

    And as Ray pointed out, you are passing schema_id to the function. The documentation shows you need to pass object_id, not schema_id. So either do one of the following:

    SELECT OBJECT_SCHEMA_NAME(o.[object_id]),* FROM sys.all_objects o;
    
    -- or
    
    SELECT SCHEMA_NAME(o.[schema_id]),* FROM sys.all_objects o;
    

    Personally, I prefer a join, e.g.:

    SELECT s.name, o.* FROM sys.all_objects AS o;
      INNER JOIN sys.schemas AS s
      ON o.[schema_id] = s.[schema_id];
    

    Why? Because this query can work across databases, whereas several of the metadata functions will return NULL or – even worse – the wrong object when called from a different database.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get Schema for a table with name Petro in SQL SErver
Possible Duplicate: Printing Table's structure/schema oracle has 'DESCRIBE' to get all the details of
I want to get list of columns of a table using GetSchema method in
Given the following select statement: Select t.name, SUM(st.row_count) as row_count From sys.dm_db_partition_stats st join
When doing... select * from students I get a Invalid object name error. Basically,
I can get the row count of all tables using this query. SELECT '['
How to get objects from the many table record? I have list of rsObjectComments
I have a model # == Schema Information # # Table name: posts #
I have a Tags table whose schema consists of only ID and Name (unique).
When working with ActiveMQ in Eclipse, you might sometimes get a schema parsing error

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.