DevPinoy.org
A Filipino Developers Community
   
Finding All User Tables and Their Columns & Data Types In SQL Server Using Object Catalog Views

Here's a quick TSQL solution that you can use to find all the User Tables and their Columns, inluding Data Types, and Column size. This is useful when you need a quick way of finding info on creating your Database's documentation. Whenever I am asked to document a new system/application or review an existing one, I always want to start from the very core of the system - mostly, this is a Database backend.

  1. SELECT t.name AS [TABLE Name], c.name AS [COLUMN Name], p.name AS [DATA Type], p.max_length AS[SIZE], CAST(p.PRECISION AS VARCHAR) +'/'+ CAST(p.scale AS VARCHAR) AS [PRECISION/Scale]
  2. FROM sys.objects AS t
  3. JOIN sys.columns AS c
  4. ON t.OBJECT_ID=c.OBJECT_ID
  5. JOIN sys.types AS p
  6. ON c.system_type_id=p.system_type_id
  7. WHERE t.type_desc='USER_TABLE';

-Marlon Ribunal

 kick it on DotNetKicks.com

[Cross-Posted From My Other Blog http://dbalink.wordpress.com]


Posted 06-16-2008 12:09 AM by marl
Copyright DevPinoy 2005-2008