Geeks With Blogs

News Copyright © 2008-2013 Paula DiTallo
Ask Paula! ...bringing you notes from the field...

 

The sys.tables and sys.columns objects will return this information for you. The following SQL statement will bring bring back all the colunns in all the tables ordered by the table name then the column name.

 

SELECT

tbl.name AS table_name,

SCHEMA_NAME

(schema_id) AS schema_name,

col

.name AS column_name

FROM

sys.tables AS tbl

INNER

JOIN sys.columns col ON tbl.OBJECT_ID = col.OBJECT_ID

ORDER

BY schema_name, table_name;

 

 

 

 

 

 

Posted on Sunday, October 10, 2010 10:32 PM Practical Answers , SQL | Back to top


Comments on this post: How do I list every table and every column in the table in SQL Server?

# re: How do I list every table and every column in the table in SQL Server?
Requesting Gravatar...
You can also use the information_Schema and not have to worry about the join and the details in the sys tables:

select table_schema as schema_name, table_name, column_name, data_type from information_schema.columns order by 1,2, 3
Left by Nick on Oct 11, 2010 1:47 PM

# ANSI equivalent
Requesting Gravatar...
SELECT TABLE_NAME, TABLE_SCHEMA, COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
ORDER BY TABLE_SCHEMA, TABLE_NAME
Left by Eddie on Oct 11, 2010 2:19 PM

Your comment:
 (will show your gravatar)
 


Copyright © Paula DiTallo | Powered by: GeeksWithBlogs.net | Join free