Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Which columns are in what tables

 
   Database Help (Home) -> Programming RSS
Next:  07 R4I :COMPRAR  
Author Message
thing

External


Since: Feb 09, 2010
Posts: 3



(Msg. 1) Posted: Mon Feb 08, 2010 11:25 pm
Post subject: Which columns are in what tables
Archived from groups: microsoft>public>sqlserver>server, others (more info?)

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

 >> Stay informed about: Which columns are in what tables 
Back to top
Login to vote
Plamen Ratchev

External


Since: Aug 20, 2008
Posts: 672



(Msg. 2) Posted: Mon Feb 08, 2010 11:25 pm
Post subject: Re: Which columns are in what tables [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

This should do it:

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

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

 >> Stay informed about: Which columns are in what tables 
Back to top
Login to vote
Erland Sommarskog2

External


Since: May 30, 2004
Posts: 2061



(Msg. 3) Posted: Tue Feb 09, 2010 6:25 pm
Post subject: Re: Which columns are in what tables [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

thing (someone@microsoft.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 DeleteThis @sommarskog.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/prodinfo/previousversions/books.mspx
 >> Stay informed about: Which columns are in what tables 
Back to top
Login to vote
thing

External


Since: Feb 09, 2010
Posts: 3



(Msg. 4) Posted: Tue Feb 16, 2010 9:25 pm
Post subject: Re: Which columns are in what tables [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Thank-you. You've pointed my in the right direction
"Plamen Ratchev" wrote in message

> This should do it:
>
> SELECT TABLE_CATALOG, TABLE_NAME, TABLE_SCHEMA, COLUMN_NAME
> FROM INFORMATION_SCHEMA.COLUMNS;
>
> --
> Plamen Ratchev
> http://www.SQLStudio.com
 >> Stay informed about: Which columns are in what tables 
Back to top
Login to vote
thing

External


Since: Feb 09, 2010
Posts: 3



(Msg. 5) Posted: Tue Feb 16, 2010 9:25 pm
Post subject: Re: Which columns are in what tables [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Thank-you. You've pointed my in the right direction
"Erland Sommarskog" wrote in message

> thing (someone@microsoft.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 RemoveThis @sommarskog.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/prodinfo/previousversions/books.mspx
>
 >> Stay informed about: Which columns are in what tables 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Compare the columns in two tables - Hi, Is there an easy and quick way to compare the column attributes of the columns in two tables. Could you please gimme an exmpale codes? Thanks, Mike

Find tables with missing columns - I am trying to find tables that are missing some columns and tried this: SELECT DISTINCT t.TABLE_NAME FROM Information_Schema.TABLES t JOIN Information_schema.Columns c on (t.TABLE_NAME = c.TABLE_NAME) WHERE (Information_schema.Columns <>..

How do I find IDENTITY columns in all tables in one databa.. - Hi all, Is there a method exists that can help me to find columns associated with "IDENTITY" property in all tables in one database? Thanks.

Finding columns in tables with specific default constraints - How can I display some specific defaults on some tables? For example some tables may have a default on a CreatingUser_ID column that default the value to suser_sid(). How could I display: 1. table name 2. column name 3. (default) constraint..

Partitioned Tables .. Order of the columns in the CLUSTERE.. - I've seen a few examples of Partitioned Table creation. Some have put the (Partition)Key as the first column. Some have it as the second column. Does anyone know if this could affect performance? Below is one table DDL, and 2 options for the..
   Database Help (Home) -> Programming All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]