dbTalk Databases Forums  

Which columns are in what tables

microsoft.public.sqlserver.tools microsoft.public.sqlserver.tools


Discuss Which columns are in what tables in the microsoft.public.sqlserver.tools forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
thing
 
Posts: n/a

Default Which columns are in what tables - 02-08-2010 , 10:55 PM






I have been asked to provide a list of all columns in all tables in a
database.
I have the output from "select * from sys.tables" and "select * from
sys.columns", but how do I know which columns are in what tables?

Thanks

Bob

Reply With Quote
  #2  
Old   
Plamen Ratchev
 
Posts: n/a

Default Re: Which columns are in what tables - 02-08-2010 , 11:02 PM






This should do it:

SELECT TABLE_CATALOG, TABLE_NAME, TABLE_SCHEMA, COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS;

--
Plamen Ratchev
http://www.SQLStudio.com

Reply With Quote
  #3  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: Which columns are in what tables - 02-09-2010 , 05:48 PM



thing (someone (AT) microsoft (DOT) com) writes:
Quote:
I have been asked to provide a list of all columns in all tables in a
database.
I have the output from "select * from sys.tables" and "select * from
sys.columns", but how do I know which columns are in what tables?
SELECT s.name AS [Schema], o.name AS [Table], c.name AS [Column]
FROM sys.schemas s
JOIN sys.objects o ON s.schema_id = o.schema_id
JOIN sys.columns c ON o.object_id = c.object_id
WHERE o.type = 'U'
ORDER BY s.name, o.name, c.column_id



--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinf...ons/books.mspx

Reply With Quote
  #4  
Old   
thing
 
Posts: n/a

Default Re: Which columns are in what tables - 02-16-2010 , 09:02 PM



Thank-you. You've pointed my in the right direction
"Plamen Ratchev" <Plamen (AT) SQLStudio (DOT) com> wrote

Quote:
This should do it:

SELECT TABLE_CATALOG, TABLE_NAME, TABLE_SCHEMA, COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS;

--
Plamen Ratchev
http://www.SQLStudio.com

Reply With Quote
  #5  
Old   
thing
 
Posts: n/a

Default Re: Which columns are in what tables - 02-16-2010 , 09:03 PM



Thank-you. You've pointed my in the right direction
"Erland Sommarskog" <esquel (AT) sommarskog (DOT) se> wrote

Quote:
thing (someone (AT) microsoft (DOT) com) writes:
I have been asked to provide a list of all columns in all tables in a
database.
I have the output from "select * from sys.tables" and "select * from
sys.columns", but how do I know which columns are in what tables?

SELECT s.name AS [Schema], o.name AS [Table], c.name AS [Column]
FROM sys.schemas s
JOIN sys.objects o ON s.schema_id = o.schema_id
JOIN sys.columns c ON o.object_id = c.object_id
WHERE o.type = 'U'
ORDER BY s.name, o.name, c.column_id



--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000:
http://www.microsoft.com/sql/prodinf...ons/books.mspx

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.