How to pull Description from a SQL Column

I have a query which pulls some table schema; however, I would like to add the Description of each column to my query results, but I do not know what the correct code is..can anyone help please?  I am using sql-200 as the back end server.
SELECT column_name AS 'Field', data_type AS 'DataType', CHARacter_maximum_length AS 'MaximumLength'
FROM information_schema.columns
WHERE (table_name = 'CustomerContact')
 ORDER BY column_name

Open in new window

dzirkelbAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Raja Jegan RSQL Server DBA & Architect, EE Solution GuideCommented:
If you have added Column descriptions using sp_addextendedproperty, then you can list it using fn_listextendedproperty function..
More info on these proc and functions here:

http://msdn.microsoft.com/en-us/library/aa259572%28SQL.80%29.aspx
http://msdn.microsoft.com/en-us/library/aa258890%28v=SQL.80%29.aspx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dzirkelbAuthor Commented:
I haven't added the descriptions like above, I am just adding them in the Table Design itself.
0
k_murli_krishnaCommented:
If you just added them in the Table Design itself:

If you like to view all the descriptions execute the following command.
select object_name(id), name from sysproperties

you can use the following system view to obtain the column
description:
         SELECT *
         FROM   sys.extended_properties
         WHERE  class = 1 AND
                     major_id = object_id(N'dbo.Course') AND
                     name = 'MS_Description'
where "dbo.Course" is one of the tables in the database.

You can have more detail about sys.extended_properties at:
http://msdn.microsoft.com/en-us/library/ms177541.aspx; and
object_id: http://msdn.microsoft.com/en-us/library/ms190328(SQL.90).aspx 

Also check out:
Select Column Information using SQL Server
http://www.geekzilla.co.uk/ViewF3E9658C-7B7A-472C-BE4A-5C25CD26C0E8.htm
0
Newly released Acronis True Image 2019

In announcing the release of the 15th Anniversary Edition of Acronis True Image 2019, the company revealed that its artificial intelligence-based anti-ransomware technology – stopped more than 200,000 ransomware attacks on 150,000 customers last year.

Raja Jegan RSQL Server DBA & Architect, EE Solution GuideCommented:
>> I am just adding them in the Table Design itself.

Adding it in Table Design is the GUI way of doing it using procedure sp_addextendedproperty..
And you can use this function to return those Descriptions in a query..
0
dzirkelbAuthor Commented:
The query listed provides the following error:

Error Source: .Net SqlClient Data Provider
Error Message: invalid object name 'sys.extended_properties'

any ideas?
0
k_murli_krishnaCommented:
System stored procedures and functions for working with extended properties
View an extended property: fn_listextendedproperty, sys.extended_properties

Both my queries look to be SQL Server 2000 ones. Correct them with help from:

sys.extended_properties (Transact-SQL)
http://msdn.microsoft.com/en-us/library/ms177541(SQL.90).aspx
Schema: How do I show the description property of a column? (for 2000, 2005)
http://databases.aspfaq.com/schema-tutorials/schema-how-do-i-show-the-description-property-of-a-column.html
Managing Extended Properties
http://www.apexsql.com/help/apexsqldoc/HTML/Step-by-Step_Guide/Extended_Properties/Managing_Extended_Properties.htm
Reporting Table Descriptions Using sys.extended_properties
http://www.sqlnewsgroups.net/group/microsoft.public.sqlserver.server/topic12221.aspx

Also Check this:
http://www.codeproject.com/KB/database/sqldoc.aspx?msg=1524160
0
Raja Jegan RSQL Server DBA & Architect, EE Solution GuideCommented:
dzirkelb,

I have been stating from the beginning to use stored procedure sp_addextendedproperty and function fn_listextendedproperty for obtaining Column Description..

But the same when mentioned by k_murli_krishna was accepted as answer without even assisted points which is not totally fair.
Can you kindly justify..
0
dzirkelbAuthor Commented:
After seeing the solutionI accepted, and then looking at the stored procedures you gave, I can see I should have noticed your solution from teh code given on the page provided.  However, still a semi-rookie to teh site.  How do I adjust points?
0
Raja Jegan RSQL Server DBA & Architect, EE Solution GuideCommented:
Ok.. Not a problem..
I have clicked on Request Attention button so that Moderators can split points on behalf of you.

Kindly take care of this in future..
0
dzirkelbAuthor Commented:
The 2nd link was exactly what I am looking for, thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.