How do I get ONLY DATATYPE and NAME of all the columns available in given table_name

Reply

Join Date: Aug 2007
Posts: 49
Reputation: tonyaim83 is an unknown quantity at this point 
Solved Threads: 0
tonyaim83 tonyaim83 is offline Offline
Light Poster

How do I get ONLY DATATYPE and NAME of all the columns available in given table_name

 
0
  #1
Oct 20th, 2008
How do I get ONLY data type and name of all the columns available in given table_name
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,158
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 136
dickersonka dickersonka is offline Offline
Veteran Poster

Re: How do I get ONLY DATATYPE and NAME of all the columns available in given table_name

 
0
  #2
Oct 20th, 2008
here is a couple more columns than you need, just so you can be clear on the query

  1. SELECT
  2. sysobjects.name AS "TABLE_NAME",
  3. syscolumns.name AS "COLUMN_NAME",
  4. systypes.name AS "DATA_TYPE",
  5. syscolumns.LENGTH AS "LENGTH"
  6. FROM
  7. sysobjects
  8. INNER JOIN
  9. syscolumns ON sysobjects.id = syscolumns.id
  10. INNER JOIN
  11. systypes ON syscolumns.xtype = systypes.xtype
  12. WHERE
  13. (sysobjects.xtype = 'U') AND
  14. sysobjects.name = 'MyTableName'
  15. ORDER BY sysobjects.name, syscolumns.colid

substitute your table name in for 'MyTableName'
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 149
Reputation: Geek-Master is an unknown quantity at this point 
Solved Threads: 6
Geek-Master's Avatar
Geek-Master Geek-Master is offline Offline
Junior Poster

Re: How do I get ONLY DATATYPE and NAME of all the columns available in given table_name

 
0
  #3
Oct 25th, 2008
In both SQL 2000 and 2005 you can run this query using the information_schema.columns

  1. SELECT
  2. data_type,
  3. column_name
  4. FROM information_schema.COLUMNS
  5. WHERE table_name = 'table'

This should do it, just make sure to run this in the correct database. If you have two table names with the same name in different schemas you may need to change the WHERE clause to this

  1. WHERE table_name = 'table'
  2. AND table_schema = 'schema'
If in doubt, reach into the trash can and remove the user guide.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the MS SQL Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC