Pages

Friday, July 30, 2010

How to get the Column information for a Table using T-SQL

in this sample I am getting the column information for a table called ‘Account’:


SELECT Columns.name AS ColumnName, ColumnTypes.name AS Type, Columns.prec AS Precision, Columns.scale AS Scale, Columns.isnullable AS IsNullableFROM sys.sysobjects AS Tables INNER JOIN sys.syscolumns AS Columns ON Columns.id = Tables.id INNER JOIN sys.systypes AS ColumnTypes ON Columns.xtype = ColumnTypes.xtypeWHERE (Tables.type = 'U') AND (Tables.name = N'Account')ORDER BY ColumnName