CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Mar 2001
    Posts
    71

    Post Sql Server Column Information

    I want to find out the description of a column in a table.
    Where does the sql stores the various properties of the columns.Such as name,Data-Type,Length,Description etc.

    and how can i get it.

    Can u help me?

  2. #2
    Join Date
    Dec 2001
    Location
    Andhra Pradesh,India.
    Posts
    72

    Thumbs up

    Open a ADODB.recordset for the table whose column's information you wish to know.
    You can then use the fields collection of the recordset object
    and get all the required information about the columns for that table.

  3. #3
    Join Date
    Mar 2001
    Posts
    71
    Hi thanks for replying.
    I know that i can get the various attributes of field by using the method that u have suggested.
    But the problem is that i can not get the description of the field.
    I want to find the description of the field.

    I hope u understand what i m trying to find out.

  4. #4
    Join Date
    Dec 2001
    Location
    Andhra Pradesh,India.
    Posts
    72
    Hi,
    You can use the stored procedure
    Code:
    sp_columns_rowset "table_name"
    This is an undocumented stored procedure that is shipped with Sql server versions 7.0 and above.
    Try it out if your sql version is 7.0 or above.

  5. #5
    Join Date
    Apr 2000
    Location
    Southampton, UK
    Posts
    329
    chanti, nice sp but this still suffers from the same problem as using the ADODB.Connection.OpenSchema method in that the Description field is *always* returned as NULL even if there is a description. I have to say that I have never found a way of retrieving this information using ADO. It may of course be possible using SQL-DMO but I have never tried, as this is the second question this week on this subject perhaps I should have a go just for fun!
    TimCottee
    I know a little about a lot of things and a lot about very little.

    Brainbench MVP For Visual Basic
    http://www.brainbench.com

    MCP, MCSD, MCDBA, CPIM

  6. #6
    Join Date
    Mar 2001
    Posts
    71
    Hi Chanti,Tim is absolutely correct.The sp that u told suffers from the same problem.

  7. #7
    Join Date
    Apr 2000
    Location
    Southampton, UK
    Posts
    329
    Seems like SQL-DMO doesn't support it either; there is no property "Description" in the properties of the column object so it looks like the only way to get this is through enterprise manager which is a bit of a crock really.
    TimCottee
    I know a little about a lot of things and a lot about very little.

    Brainbench MVP For Visual Basic
    http://www.brainbench.com

    MCP, MCSD, MCDBA, CPIM

  8. #8
    Join Date
    Dec 2001
    Location
    Andhra Pradesh,India.
    Posts
    72

    Thumbs up

    Hi,
    I got it allast.
    Use the sql query show below
    Code:
    SELECT   *
    FROM   ::fn_listextendedproperty (NULL, 'user', 'user_name', 'table', 'table_name', 'column', default)
    replace the user_name with your sql user name and
    table_name with the table to which the column belongs.

    This should work guys.
    I checked it out.

  9. #9
    Join Date
    Apr 2000
    Location
    Southampton, UK
    Posts
    329
    Doesn't return a pre-defined "Description" property from my table, even using all defaults logged in as "sa" I get no values returned but as I haven't added any extended properties I am not really surprised. I still maintain that there is no known way to get the description property, I am ever hopeful of course that somebody will come up with a solution that works (for me at least).
    TimCottee
    I know a little about a lot of things and a lot about very little.

    Brainbench MVP For Visual Basic
    http://www.brainbench.com

    MCP, MCSD, MCDBA, CPIM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured