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 systypes 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
)
-----上面的是创建一个视图。
-----下面的是查看。
select * from alldata where tablename='test' ----表名。视图名。。。。。