Proper query

Igor Korot 26 Reputation points
2025-01-15T06:50:47.5833333+00:00

Hi, ALL,

Right now I'm using following query

SELECT object_id FROM sys.objects o, sys.schemas s WHERE s.schema_id = o.schema_id AND o.name = ? AND s.name = ?

Is there a simple way to bring in sys.databases table?

Thank you.

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,293 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. 博雄 胡 545 Reputation points
    2025-01-15T07:09:43.9866667+00:00

    easy

    SELECT object_id,apply1.* FROM sys.objects o, sys.schemas s cross apply(select * from sys.databases d where d.database_id = db_id())apply1 WHERE s.schema_id = o.schema_id AND o.name = ? AND s.name = ?
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.