retrieve column name

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • RP

    #1

    retrieve column name

    I want to retrieve column names (Exact field names) of a table. How to
    do that?

  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: retrieve column name

    RP,

    That depends completely on the underlying data source. For SQL Server
    2000 and below, you can use the syscolumns table. For SQL Server 2005,
    sys.columns is recommended. If you are using another database system, then
    that will have its own way of retreiving this info.

    You can create a connection and then call the GetSchema method on it.
    However, the way that the schemas are defined and what they return are
    provider-specific, so you will need to have some knowledge beforehand.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "RP" <rpk.general@gm ail.comwrote in message
    news:1188320271 .928794.96010@q 5g2000prf.googl egroups.com...
    >I want to retrieve column names (Exact field names) of a table. How to
    do that?
    >

    Comment

    • Mythran

      #3
      Re: retrieve column name



      "RP" <rpk.general@gm ail.comwrote in message
      news:1188320271 .928794.96010@q 5g2000prf.googl egroups.com...
      >I want to retrieve column names (Exact field names) of a table. How to
      do that?
      >
      Depends on the DBMS (if those are the "column"s and "table"s you are
      referring to). If SQL Server 2000, you can call the FillSchema method or
      execute the sp_columns stored procedure on the server itself.

      HTH,
      Mythran


      Comment

      • RP

        #4
        Re: retrieve column name

        I am using SQL Server 2005. Can it be retrieved using SQL?

        Comment

        • Nicholas Paldino [.NET/C# MVP]

          #5
          Re: retrieve column name

          RP,

          Yes, as Mythran stated, you can execute the sp_columns stored procedure,
          or you can perform a select against sys.columns (where the object_id is the
          id of the table you want to get the columns for).


          --
          - Nicholas Paldino [.NET/C# MVP]
          - mvp@spam.guard. caspershouse.co m

          "RP" <rpk.general@gm ail.comwrote in message
          news:1188322217 .506639.126840@ q4g2000prc.goog legroups.com...
          >I am using SQL Server 2005. Can it be retrieved using SQL?
          >

          Comment

          • RP

            #6
            Re: retrieve column name

            How to know the object id of my table?

            On Aug 28, 10:40 pm, "Nicholas Paldino [.NET/C# MVP]"
            <m...@spam.guar d.caspershouse. comwrote:
            ..... you can execute the sp_columns stored procedure,
            or you can perform a select against sys.columns (where the object_id is the
            id of the table you want to get the columns for).

            Comment

            • zacks@construction-imaging.com

              #7
              Re: retrieve column name

              On Aug 28, 1:30 pm, RP <rpk.gene...@gm ail.comwrote:
              I am using SQL Server 2005. Can it be retrieved using SQL?
              The "safest" way to get metatdata from SQL Server like table list and
              column lists is to use one of the INFORMATION_SCH EMA Views. For a list
              of tables in the current database:

              select * from information_sch ema.tables


              Comment

              • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

                #8
                Re: retrieve column name

                zacks@construct ion-imaging.com wrote:
                On Aug 28, 1:30 pm, RP <rpk.gene...@gm ail.comwrote:
                >I am using SQL Server 2005. Can it be retrieved using SQL?
                >
                The "safest" way to get metatdata from SQL Server like table list and
                column lists is to use one of the INFORMATION_SCH EMA Views. For a list
                of tables in the current database:
                >
                select * from information_sch ema.tables
                SELECT COLUMN_NAME
                FROM INFORMATION_SCH EMA.COLUMNS
                WHERE TABLE_NAME='xxx x'

                to be more specifically.

                Arne

                Comment

                • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

                  #9
                  Re: retrieve column name

                  Nicholas Paldino [.NET/C# MVP] wrote:
                  That depends completely on the underlying data source. For SQL Server
                  2000 and below, you can use the syscolumns table. For SQL Server 2005,
                  sys.columns is recommended. If you are using another database system, then
                  that will have its own way of retreiving this info.
                  >
                  You can create a connection and then call the GetSchema method on it.
                  However, the way that the schemas are defined and what they return are
                  provider-specific, so you will need to have some knowledge beforehand.
                  Using INFORMATION_SCH EMA's should be the recommended way.

                  Seems rather silly to use a database specific function to
                  do something that is standardized.

                  Arne

                  Comment

                  Working...