SQL Server List Tables And Columns
The code below can be used to list tables and columns in a database provided your user account has permission to do so.
–List Column Names
SELECT COLUMN_NAME, TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_CATALOG = 'YOUR_DB_NAME'
–List Tables
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_CATALOG = 'YOUR_DB_NAME'
–List Views
SELECT *
FROM INFORMATION_SCHEMA.VIEWS
WHERE TABLE_CATALOG = 'YOUR_DB_NAME'
–List All Columns in All Views
SELECT *
FROM INFORMATION_SCHEMA.VIEW_COLUMN_USAGE
WHERE TABLE_CATALOG = 'YOUR_DB_NAME'
–List Stored Procedures
SELECT *
FROM sys.procedures
–List a Stored Procedure Script
EXEC sp_HelpText N'YourStoredProc'
#SQLServer