The code looks like this:
/*********************************sqlserver queries All tables in the database and their field properties *********************************/SELECT( Case whenA.colorder= 1 ThenD.nameELSE "' END) asTable name,--returns null if the table name is the sameA.colorder asfield ordinal, A.name asfield name, ( Case when ColumnProperty(a.ID, A.name,'isidentity')= 1 Then '√' ELSE "' END) asidentification, ( Case when(SELECT COUNT(*) fromsysobjects--Query primary Key WHERE(Nameinch ( SELECTname fromsysindexesWHERE(ID=a.id) and(indidinch ( SELECTindid fromSysindexkeysWHERE(ID=a.id) and(colidinch ( SELECTcolid fromsyscolumns WHERE(ID=a.id) and(Name=( a.name) ))))) and(xtype= 'PK' ) ) > 0 Then '√' ELSE "' END) asPrimary KEY,--Query primary key endB.name astype, A.length asthe number of bytes consumed,ColumnProperty(a.ID, A.name,'PRECISION') aslength,ISNULL(ColumnProperty(a.ID, A.name,' Scale'),0) asNumber of decimal digits, ( Case whenA.isnullable= 1 Then '√' ELSE "' END) asallow NULL,ISNULL(E.text,"') asdefault value,ISNULL(g.[value],"') asField Description fromsyscolumns a Left JOINSystypes b onA.xtype=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_idORDER bya.id, A.colorder;
The query results are as follows:
SQL Server queries all tables and their field properties in the database