1.首先见两个表test1,test2
2.目标:先查询一下test1表格和字段的注释
select a.value,a.*,'---------',o.*
from sysproperties a--sysproperties.value存储了表格和字段的说明
inner join sysobjects o on a.id=o.id and o.name='test1' and o.xtype='U'--id表示这个对象的编号,'U'表示这个对象的是用户表
查询结果如下: 可以看到value中不但查出了表格的注释还查询出了字段的注释而且id是一样的,说明字段和表共用一个编号,那么如何区别是表格的注释还是字段的注释呢?,乖乖,原来type字段等于3表示是表格的注释,4表示是字段的注释,我们已经把sysproperties和sysobjects全部的字段都查询出来了,但是却看不到字段的名字,查询字段对应注释就成为了下一个目标
laolaowhn
value | id | smallid | type | name | value | Expr2 | name | id | xtype | uid | info | status | base_schema_ver | replinfo | parent_obj | crdate | ftcatid | schema_ver | stats_schema_ver | type | userstat | sysstat | indexdel | refdate | version | deltrig | instrig | updtrig | seltrig | category | cache |
test1 表注释 | 517576882 | 0 | 3 | MS_Description | test1 表注释 | --------- | test1 | 517576882 | U | 1 | 27 | 1610615063 | 96 | 0 | 0 | 2009-9-29 16:07 | 0 | 96 | 0 | U | 1 | 8307 | 0 | 2009-9-29 16:07 | 0 | 0 | 0 | 0 | 0 | 16904 | 0 |
ID 注释 | 517576882 | 1 | 4 | MS_Description | ID 注释 | --------- | test1 | 517576882 | U | 1 | 27 | 1610615063 | 96 | 0 | 0 | 2009-9-29 16:07 | 0 | 96 | 0 | U | 1 | 8307 | 0 | 2009-9-29 16:07 | 0 | 0 | 0 | 0 | 0 | 16904 | 0 |
3.目标查询字段对应的注释:
select c.name,a.value, a.*,'________',o.*,'________',c.*
from SysProperties a --sysproperties。value存储了表格和字段的说明
inner join sysobjects o on a.id=o.id--存储了全部对象的编号名称等信息
inner join syscolumns c on a.id=c.id and a.smallid=c.colid --id表示这个对象的编号,colid表示列的编号,说明c.id还是存储了表格的编号
where o.name = 'test1'
查询结果如下:可以看到 a.smallid=c.colid把表的注释过滤掉了,
name | value | id | smallid | type | name | value | Expr3 | name | id | xtype | uid | info | status | base_schema_ver | replinfo | parent_obj | crdate | ftcatid | schema_ver | stats_schema_ver | type | userstat | sysstat | indexdel | refdate | version | deltrig | instrig | updtrig | seltrig | category | cache | Expr4 | name | id | xtype | typestat | xusertype | length | xprec | xscale | colid | xoffset | bitpos | reserved | colstat | cdefault | domain | number | colorder | autoval | offset | collationid | language | status | type | usertype | printfmt | prec | scale | iscomputed | isoutparamisnullable collation tdscollation |
ID | ID 注释 | 517576882 | 1 | 4 | MS_Description | ID 注释 | ________ | test1 | 517576882 | U | 1 | 27 | 1610615063 | 96 | 0 | 0 | 2009-9-29 16:07 | 0 | 96 | 0 | U | 1 | 8307 | 0 | 2009-9-29 16:07 | 0 | 0 | 0 | 0 | 0 | 16904 | 0 | ________ | ID | 517576882 | 56 | 1 | 56 | 4 | 10 | 0 | 1 | 4 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | null | 2 |
| 0 | 0 | 56 | 7 |
| 10 | 0 | 0 | 00 null |