遍历数据库中的用户存储过程,获得每个存储过程的参数名、参数类型、存储过程名称等信息以xml的形式保存

小弟想要能够遍历数据库中的用户存储过程,希望能够获得每个存储过程的参数名、参数类型、存储过程名称等信息
以xml的形式保存,用于对数据库的映射

有谁知道吗?分不够可以加。
---------------------------------------------------------------
use 数据库名
go

--存储过程结构生成XML文档

create table ##tb(re varchar(8000))
insert into ##tb
select '

<数据库>'+db_name()

insert into ##tb
select case b.colid when 1 then '<存储过程名称>'+a.name else ' ' end+'
<参数 参数名称="'+b.name
+'" 参数类型="'+c.name
+case when c.name in ('binary','char','nchar','nvarchar','varbinary','varchar','float','real')
then '('+cast(b.prec as varchar)+')'
when c.name in ('decimal','numeric')
then '('+cast(b.prec as varchar)+','+cast(b.scale as varchar)+')'
else '' end+'">

'
+case b.colid when (select max(colid) from syscolumns where id=a.id)
then '

' else '' end
from sysobjects a
join syscolumns b on a.id=b.id
join systypes c on b.xusertype=c.xusertype
where a.xtype='P' and a.status>=0
order by a.name,b.colid

insert into ##tb values('

')

exec master..xp_cmdshell 'bcp ##tb out c:\a.xml /c'
drop table ##tb

Published At
Categories with 数据库类
Tagged with
comments powered by Disqus