Create view alldata
As
(
Select top 100000000 D. xtype, D. Name n 'tablename', A. colorder n 'fieldnumber', A. Name n 'fieldname ',
(Case when columnproperty (A. ID, A. Name, 'isidentity ') = 1 then '1' else '0' end) n'isidentifier ',
(Case when (select count (*)
From sysobjects where (name in (Select name from sysindexes
Where (ID = A. ID) and (indid in (select indid from sysindexkeys
Where (ID = A. ID) and (colid in (select colid from syscolumns
Where (ID = A. ID) and (name = A. Name) and (xtype = 'pk')> 0
Then '1' else '0' end) n 'iskeyfield', B. Name n 'fieldtype', A. length N 'fieldsize ',
Columnproperty (A. ID, A. Name, 'precision ') as n' fieldlength ',
Isnull (columnproperty (A. ID, A. Name, 'Scale'), 0) as n' decimaldigits ',
(Case when a. isnullable = 1 then '1' else '0' end) n'allownull', isnull (E. Text, '') n'defaultvalue ',
Isnull (G. [value], '') as n' fielddescn'
From syscolumns a left join policypes B on A. xtype = B. xusertype inner join sysobjects d
On a. ID = D. id and D. Name <> 'dtproperties' left join syscomments e on A. cdefault = E. ID
Left join sysproperties g on A. ID = G. ID and A. colid = G. smallid order by object_name (A. ID), A. colorder
)
----- Create a view.
----- See the following.
Select * From alldata where tablename = 'test' ---- table name. View name .....