Cari Blog Ini

17 September 2010

IT - SQL Server - Query - For Display All Column in Table

/*
NOTE : QUERY FOR DISPLAY ALL COLUMN IN TABLE
*/


SELECT
CAST (ordinal_position AS VARCHAR(3)) AS Field,
CAST(column_name AS VARCHAR(25)) AS FieldName,
CAST(data_type AS VARCHAR(15)) AS Type,
CAST(character_maximum_length AS VARCHAR(5)) AS Width
FROM information_schema.COLUMNS join sysobjects
ON sysobjects.NAME=information_schema.COLUMNS.table_name
WHERE xtype='u' and type='u' and table_name='Products'
ORDER BY ordinal_position


Results :