| | |
How do I get ONLY DATATYPE and NAME of all the columns available in given table_name
Please support our MS SQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Aug 2007
Posts: 49
Reputation:
Solved Threads: 0
How do I get ONLY DATATYPE and NAME of all the columns available in given table_name
0
#1 Oct 20th, 2008
•
•
Join Date: Aug 2008
Posts: 1,158
Reputation:
Solved Threads: 136
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
substitute your table name in for 'MyTableName'
MS SQL Syntax (Toggle Plain Text)
SELECT sysobjects.name AS "TABLE_NAME", syscolumns.name AS "COLUMN_NAME", systypes.name AS "DATA_TYPE", syscolumns.LENGTH AS "LENGTH" FROM sysobjects INNER JOIN syscolumns ON sysobjects.id = syscolumns.id INNER JOIN systypes ON syscolumns.xtype = systypes.xtype WHERE (sysobjects.xtype = 'U') AND sysobjects.name = 'MyTableName' ORDER BY sysobjects.name, syscolumns.colid
substitute your table name in for 'MyTableName'
Custom Application & Software Development
www.houseshark.net
www.houseshark.net
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
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
MS SQL Syntax (Toggle Plain Text)
SELECT data_type, column_name FROM information_schema.COLUMNS 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
MS SQL Syntax (Toggle Plain Text)
WHERE table_name = 'table' AND table_schema = 'schema'
If in doubt, reach into the trash can and remove the user guide.
![]() |
Other Threads in the MS SQL Forum
- Previous Thread: Trouble Ticket System
- Next Thread: Need help with a trigger
| Thread Tools | Search this Thread |






