Cari Blog Ini

28 Juni 2012

How To Check All Columns in Table of Database

----------------------------------------------------------
-----code:start
----------------------------------------------------------
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='MsKaryawan'
order by ordinal_position
----------------------------------------------------------
-----code:end
----------------------------------------------------------

Result Messages:

Field FieldName                 Type            Width
----- ------------------------- --------------- -----
1     NIK                              char            8
2     Nama                           char            30
3     Alamat                        char            60
4     Alamat1                      char            60
5     email                            char            50
6     KdPos                         char            5
7     TempatLahir               char            30
8     TglLahir                      datetime        NULL
9     Agama                        char            1