给数据库字段添加注释,并且可以通过sql语句查询
查看字段注释
1 Create view FieldDesc
2 As
3 select o.name as oname, c.name as cname,convert(varchar(30),p.value) as value,p.smallid as psmallid,t.name as tname
4 from syscolumns c
5 join systypes t on c.xtype = t.xtype
6 join sysobjects o on o.id=c.id
7 left join sysproperties p on p.smallid=c.colid and p.id=o.id
8 where o.xtype='U'
2 As
3 select o.name as oname, c.name as cname,convert(varchar(30),p.value) as value,p.smallid as psmallid,t.name as tname
4 from syscolumns c
5 join systypes t on c.xtype = t.xtype
6 join sysobjects o on o.id=c.id
7 left join sysproperties p on p.smallid=c.colid and p.id=o.id
8 where o.xtype='U'
上面是创建注释查询试图。通过上面的语句可以看到某表某字段的注释
--------------------------------------
创建注释(N'user', N'dbo', N'table' 为固定的)
--为表添加描述信息
EXECUTE sp_addextendedproperty N'MS_Description', '人员信息表', N'user', N'dbo', N'table', N'表', NULL, NULL
--为字段a1添加描述信息
EXECUTE sp_addextendedproperty N'MS_Description', '姓名', N'user', N'dbo', N'table', N'表', N'column', N'a1'
--为字段a2添加描述信息
EXECUTE sp_addextendedproperty N'MS_Description', '性别', N'user', N'dbo', N'table', N'表', N'column', N'a2'
--更新表中列a1的描述属性:
EXEC sp_updateextendedproperty 'MS_Description','字段1','user',dbo,'table','表','column',a1
--删除表中列a1的描述属性:
EXEC sp_dropextendedproperty 'MS_Description','user',dbo,'table','表','column',a1