Is there a SQL statement that will list the names of all the tables, views, and stored procs from MS SQL Server database, ordered by schema name?
I would like to generate an Excel spreadsheet from this list with the columns: schema, type (table, view, stored proc), and name.
Here's what you asked for:
select
s.name as [Schema],
o.type_desc as [Type],
o.name as [Name]
from
sys.all_objects o
inner join sys.schemas s on s.schema_id = o.schema_id
where
o.type in ('U', 'V', 'P') -- tables, views, and stored procedures
order by
s.name
You can create a query using the system views INFORMATION_SCHEMA.TABLES
, INFORMATION_SCHEMA.VIEWS
and INFORMATION_SCHEMA.COLUMNS
Edit: Oh and INFORMATION_SCHEMA.ROUTINES
for stored procs
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