SQL Server Query table structure information-field description, type, length and other information synthesis syntax.
SELECTTable name=D.name,--If a.colorder=1 then d.name else ' end,Table description= Case whenA.colorder=1 Then IsNull(F.value,"')Else "' End, Field ordinal=a.colorder, field name=a.name, Logo= Case when ColumnProperty(A.id,a.name,'isidentity')=1 Then '√'Else "' End, PRIMARY key= Case when exists(SELECT 1 fromsysobjectswhereXtype='PK' andParent_obj=a.ID andNameinch ( SELECTName fromsysindexesWHEREIndidinch( SELECTIndid fromSysindexkeysWHEREId=a.ID andColid=A.colid))) Then '√' Else "' End, type=b.name, number of bytes occupied=a.length, Length= ColumnProperty(A.id,a.name,'PRECISION'), number of decimal digits= IsNull(ColumnProperty(A.id,a.name,' Scale'),0), allow null= Case whenA.isnullable=1 Then '√'Else "' End, the default value= IsNull(E.text,"'), field description= IsNull(g.[value],"') fromsyscolumns a Left Joinsystypes b onA.xusertype=B.xusertypeInner Joinsysobjects D ona.id=D.id andD.xtype='U' andD.name<>'dtproperties' Left Joinsyscomments e onA.cdefault=e.id Left Joinsys.extended_properties G ona.id=g.major_id andA.colid=g.minor_id Left Joinsys.extended_properties F ond.id=f.major_id andf.minor_id=0whereD.name='mrc_icsubordinate' --If you query only the specified table, add this conditionOrder byA.id,a.colorder
SQL Server Query table structure information-field description, type, length, and more