MSAccessRookie
05-27-2008, 07:40 AM
Is there an easy way to query a list of the columns in each table of an SQL Server Database? I need a report that has such a list for each table in the database. I can do it by hand, but I was hoping to be able to do it more quickly than that. I know that Oracle allows the user to create a list using one of the system tables, and wondered if SQL Server had a similar feature.
georgedwilkinson
05-27-2008, 08:08 AM
Look at syscolumns. The table names that start with "sys" are the tables that contain information about the databases objects.
Be cautious.
MSAccessRookie
05-27-2008, 08:37 AM
I tried
SELECT *
FROM sys.syscolumns
ORDER BY name
and got what appears to be a complete list of every column that is in the entire database. The problem with the list is that there is no obvious cross reference to the tables or views that the columns belong to.
What am I missing here?
MSAccessRookie
05-27-2008, 11:52 AM
UPDATE:
Looks like I found what I was looking for. There were two tables (sys.tables and sys.all_columns) that had a common column called object_id, so the following query gave me what I was looking for. Thanks for pointing me in the right direction.
----------------------------------------------------
SELECT sys.tables.Name, sys.all_columns.Name
FROM sys.tables INNER JOIN sys.all_columns ON sys.tables.object_id = sys.all_columns.object_id
ORDER BY sys.tables.Name
----------------------------------------------------