获取SQLSERVER一张表里面的常用字段信息
发布时间:2020-12-12 14:52:48 所属栏目:MsSql教程 来源:网络整理
导读:SELECTTableName=d.name,--表名称FieldNo=a.colorder,--字段编号FieldName=a.name,--字段名称IsIdentity=case when COLUMNPROPERTY(a.id,a.name,'IsIdentity')=1 then 'true'else 'false' end,--是否自增PrimaryKey=case when exists( SELECT 1 FROM sysobje
SELECT TableName=d.name,--表名称 FieldNo=a.colorder,--字段编号 FieldName=a.name,--字段名称 IsIdentity=case when COLUMNPROPERTY(a.id,a.name,'IsIdentity')=1 then 'true'else 'false' end,--是否自增 PrimaryKey=case when exists ( SELECT 1 FROM sysobjects where xtype='PK' and name in ( SELECT name FROM sysindexes WHERE indid in ( SELECT indid FROM sysindexkeys WHERE id = a.id AND colid=a.colid ) ) ) then 'true' else 'false' end,--是否主键 FieldType=b.name,--字段类型 FieldLength=a.length,--字段长度 FieldSize=COLUMNPROPERTY(a.id,'PRECISION'),--字段大小 FieldScale=isnull(COLUMNPROPERTY(a.id,'Scale'),0),--小数位数 FieldAllowNull=case when a.isnullable=1 then 'true' else 'false' end,--是否为空 DefaultValue=isnull(e.text,''),--默认值 FieldRemark=isnull(g.[value],'')--字段说明 FROM syscolumns a left join systypes b on a.xtype=b.xusertype inner join sysobjects d on a.id=d.id and d.xtype='U' and d.name<>'dtproperties' left join syscomments e on a.cdefault=e.id left join sys.extended_properties g on a.id=g.major_id and a.colid=g.minor_id--SQL2005 --left join sysproperties g on a.id=g.id and a.colid=g.smallid where d.name='TableName' order by a.id,a.colorder? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
热点阅读