Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Column lenth as read from syscolumns table

Column lenth as read from syscolumns table

Scheduled Pinned Locked Moved Database
databasehelpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    WBurgMo
    wrote on last edited by
    #1

    I am trying to come up with a query to determine the structure of a table. So far I have come up with the following query: SELECT SC.name, SC.length FROM syscolumns SC inner join sysobjects SO on SO.id = SC.id where SO.name = 'Customers' The problem is that the "length" column is twice the size it should be. Is there a flaw in my query or do I just have to divide the "length" by two? Thanks James Johnson

    A 1 Reply Last reply
    0
    • W WBurgMo

      I am trying to come up with a query to determine the structure of a table. So far I have come up with the following query: SELECT SC.name, SC.length FROM syscolumns SC inner join sysobjects SO on SO.id = SC.id where SO.name = 'Customers' The problem is that the "length" column is twice the size it should be. Is there a flaw in my query or do I just have to divide the "length" by two? Thanks James Johnson

      A Offline
      A Offline
      Ashfield
      wrote on last edited by
      #2

      Assuming you are using sql server 2000 or later try this: select * from information_schema.columns where table_name = 'Customers' It gives you all the information about the table structure. Hope this helps

      Bob Ashfield Consultants Ltd

      W 1 Reply Last reply
      0
      • A Ashfield

        Assuming you are using sql server 2000 or later try this: select * from information_schema.columns where table_name = 'Customers' It gives you all the information about the table structure. Hope this helps

        Bob Ashfield Consultants Ltd

        W Offline
        W Offline
        WBurgMo
        wrote on last edited by
        #3

        What I ended up doing is creating a command to execute the following Select top 1 * from Customers Then DataReader dr = cmd.ExecuteReader(); DataTable dt = dr.GetSchemaTable(); The resulting DataTable contains all of the information I need. Thanks James Johnson

        A 1 Reply Last reply
        0
        • W WBurgMo

          What I ended up doing is creating a command to execute the following Select top 1 * from Customers Then DataReader dr = cmd.ExecuteReader(); DataTable dt = dr.GetSchemaTable(); The resulting DataTable contains all of the information I need. Thanks James Johnson

          A Offline
          A Offline
          Ashfield
          wrote on last edited by
          #4

          Thats one way :) Even better would be Select * from Customers where 1 = 2 Which will give you an empty table and use less resource on the server

          Bob Ashfield Consultants Ltd

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups