在winform程序开发中,涉及到对某个表的组合查询时会到数据库中提取表的字段名和说明,以便于用户选择查询,在C#中使用语句比较麻烦,写到存储过程中就比较方便了。
USE [schoolDB]GO/****** Object: StoredProcedure [dbo].[sp_showcolumn] Script Date: 06/03/2016 16:45:26 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER proc [dbo].[sp_showcolumn] @tablename varchar(30)as select c.name as 字段名,p.value as 说明 from sysobjects o left join syscolumns c on o.id=c.id left join sys.extended_properties p on p.major_id=c.id and p.minor_id=c.colid and p.name='MS_Description' left join systypes t on c.xusertype=t.xusertypewhere o.type='u' and o.name=@tablename
查询更多信息的sql语句:
select o.name as tableName,c.name as columnName,t.name as columnType,p.value as columnDescription from sysobjects o left join syscolumns c on o.id=c.id left join sys.extended_properties p on p.major_id=c.id and p.minor_id=c.colid and p.name='MS_Description' left join systypes t on c.xusertype=t.xusertypewhere o.type='u' and o.name='cdxmain'