I would like to list all objects of a particular database in SQL Server. I created a query as shown below:
select name, type_desc from sys.objects
WHERE type in ( 'C', 'D', 'F', 'L', 'P', 'PK', 'RF', 'TR', 'UQ', 'V', 'X' )
union
select name, type_desc from sys.indexes
order by name
However, this query list all objects of ALL databases rather than a particular database.
My question is: Is there a way to query all objects of just a particular database?
This is what I use.
SELECT o.type_desc AS Object_Type
, s.name AS Schema_Name
, o.name AS Object_Name
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
List all procs, views, tables, functions in Sql Server:
SELECT DISTINCT
o.name AS Object_Name,
o.type_desc
FROM sys.sql_modules m
INNER JOIN
sys.objects o
ON m.object_id = o.object_id
--WHERE '.' + m.definition + '.' LIKE '%[^a-z]employeeid[^a-z]%'
order by type_desc, object_name
The comment is if you want to search for a particular (whole) word.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With