July 31, 2008

Describe a table in SQL Server 2005

Here's a quick snippet of SQL that allows you to describe a table in a SQL Server 2005 database, similar to the DESC or DESCRIBE command in Oracle and MySQL:

SELECT column_name, data_type,column_default, is_nullable, character_maximum_lenght, numeric_precision, datetime_precision
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name='MyTableName'

Detailed info
on INFORMATION_SCHEMA: http://msdn.microsoft.com/en-us/library/ms186778.aspx