patternsqlMinor
Display all tables and their columns
Viewed 0 times
tablescolumnsallanddisplaytheir
Problem
Is there a way to display the layouts for all the tables to see their columns? I am trying to find tables with a certain column names.
I am using the web app Web Data Administrator
Example:
is there a way to get a display like that?
I am using the web app Web Data Administrator
Example:
table1
- column 1
- column 2
table2
- column 1is there a way to get a display like that?
Solution
Here is a start, if I can guess that by
This doesn't provide exactly the output you want, but surely your presentation tier can - while it is looping through all of the rows - figure out to only list a table when it comes across a new one.
row you actually mean column:SELECT
[table] = QUOTENAME(OBJECT_SCHEMA_NAME([t.object_id])) +'.'+ QUOTENAME(t.name),
[column] = c.name
FROM sys.tables AS t
INNER JOIN sys.columns AS c
ON t.[object_id] = c.[object_id]
ORDER BY t.name, c.column_id;This doesn't provide exactly the output you want, but surely your presentation tier can - while it is looping through all of the rows - figure out to only list a table when it comes across a new one.
Code Snippets
SELECT
[table] = QUOTENAME(OBJECT_SCHEMA_NAME([t.object_id])) +'.'+ QUOTENAME(t.name),
[column] = c.name
FROM sys.tables AS t
INNER JOIN sys.columns AS c
ON t.[object_id] = c.[object_id]
ORDER BY t.name, c.column_id;Context
StackExchange Database Administrators Q#29398, answer score: 9
Revisions (0)
No revisions yet.