⟩ How To List All Objects in a Given Schema?
If you are wonder what objects are stored in a given schema as an object container, you can use view "sys.objects" to get a list of all objects in a schema. The tutorial exercise shows you how to list all objects in schema "ggl" and "dbo":
-- Login with 'sa'
USE GlobalGuideLineDatabase;
GO
-- What is "ggl"?
SELECT o.name, o.schema_id, o.type_descFROM sys.objects o, sys.schemas s
WHERE o.schema_id = s.schema_id
AND s.name = 'ggl';
GO
name schema_id type_desc
------------------------------ ---------- ------------------
test 5 USER_TABLE
ggl_links 5 USER_TABLE
UQ__ggl_links__4222D4EF 5 UNIQUE_CONSTRAINT
DF__ggl_links__creat__4316F928 5 DEFAULT_CONSTRAINT
SELECT o.name, o.schema_id, o.type_desc
FROM sys.objects o, sys.schemas s
WHERE o.schema_id = s.schema_id
AND s.name = 'dbo';
GO