Skip to content

Instantly share code, notes, and snippets.

@wbhinton
Created December 3, 2019 16:20
Show Gist options
  • Save wbhinton/2e43d020a4fc3ca911e39dc86b356a68 to your computer and use it in GitHub Desktop.
Save wbhinton/2e43d020a4fc3ca911e39dc86b356a68 to your computer and use it in GitHub Desktop.
List all tables in a database with descriptions
EXEC sp_tables;
-- Note this method returns both table and views.
--OR
SELECT @@Servername AS ServerName ,
TABLE_CATALOG ,
TABLE_SCHEMA ,
TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
ORDER BY TABLE_NAME
;
--OR
SELECT @@Servername AS ServerName ,
DB_NAME() AS DBName ,
o.name AS 'TableName' ,
o.[Type] ,
o.create_date
FROM sys.objects o
WHERE o.Type = 'U'
-- User table
ORDER BY o.name;
--OR
SELECT @@Servername AS ServerName ,
DB_NAME() AS DBName ,
t.Name AS TableName,
t.[Type],
t.create_date
FROM sys.tables t
ORDER BY t.Name;
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment