SQL – getting table info

Sometimes I’ve had the need to use SQL to go and get table information i.e is a field varchar or int etc.

For MS SQL server you can use the following to get info on a table


SELECT RIGHT(syscolumns.name, LEN(syscolumns.name)) AS dbFieldName, systypes.name AS typename, syscolumns.length AS maxlength, syscolumns.xprec AS [precision], syscolumns.xscale AS scale, syscolumns.isnullable AS isnullable
FROM syscolumns INNER JOIN
sysobjects ON sysobjects.id = syscolumns.id INNER JOIN
systypes ON syscolumns.xtype = systypes.xtype
WHERE (sysobjects.name = THE_TABLE_NAME)
ORDER BY syscolumns.colorder

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Live
  • Google Bookmarks
  • BlinkList
  • FriendFeed
  • Ping.fm
  • StumbleUpon
  • Technorati
  • Mixx
  • Reddit
  • Blogosphere News
  • Fark
  • Identi.ca
  • LinkedIn
  • Sphinn
  • TwitThis
  • E-mail this story to a friend!
  • Print this article!

Related posts:

  1. SQL – The case for CASE The Transact SQL Case statement is a particularly useful piece...