By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,379 Members | 1,435 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,379 IT Pros & Developers. It's quick & easy.

List Columns in a Table in SQL 2005

P: n/a
Hi, I know sys.tables and sys.columns gives me a list of tables and
columns in a SQL 2005 database.

How can I list Columns in a specific Table please?

Thanks in advance,
Ronny
Apr 2 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
You have to join both catalog views by object_id:

SELECT SCHEMA_NAME(T.schema_id) AS 'Schema',
T.name AS 'Table Name',
C.name AS 'Column Name'
FROM sys.tables AS T
JOIN sys.columns AS C
ON T.object_id = C.object_id
WHERE T.type = 'U'
AND T.name = 'MyTableName';

Or you can use:

SELECT table_schema,
table_name,
column_name
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'MyTableName';
HTH,

Plamen Ratchev
http://www.SQLStudio.com
Apr 2 '08 #2

P: n/a
ro******@hotmail.co.uk wrote:
Hi, I know sys.tables and sys.columns gives me a list of tables and
columns in a SQL 2005 database.

How can I list Columns in a specific Table please?

Thanks in advance,
Ronny
desc tablename
Apr 2 '08 #3

P: n/a
lark wrote:
ro******@hotmail.co.uk wrote:
>Hi, I know sys.tables and sys.columns gives me a list of tables and
columns in a SQL 2005 database.

How can I list Columns in a specific Table please?

Thanks in advance,
Ronny
desc tablename
scratch that. it doesn't work in ms sqlserver.
Apr 2 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.