Tuesday, April 19, 2022

.::: How to list all objects of a particular database in SQL Server (List Object Name, Object ID) :::.

   SELECT @@servername as ServerName,db_name() as DbName, o.type_desc AS Object_Type
       ,  s.name AS Schema_Name
       ,  o.name AS Object_Name,object_id
       ,  o.name AS ObjectName
    FROM  sys.objects o
    JOIN  sys.schemas s
      ON  s.schema_id = o.schema_id
   WHERE  o.type NOT IN ('S'  --SYSTEM_TABLE
                        ,'PK' --PRIMARY_KEY_CONSTRAINT
                        ,'D'  --DEFAULT_CONSTRAINT
                        ,'C'  --CHECK_CONSTRAINT
                        ,'F'  --FOREIGN_KEY_CONSTRAINT
                        ,'IT' --INTERNAL_TABLE
                        ,'SQ' --SERVICE_QUEUE
                        ,'TR' --SQL_TRIGGER
                        ,'UQ' --UNIQUE_CONSTRAINT
                        )
ORDER BY  Object_Type
       ,  SCHEMA_NAME
       ,  Object_Name


 

No comments:

Post a Comment

Popular Posts