发布网友 发布时间:2022-04-24 01:45
共2个回答
懂视网 时间:2022-05-03 07:31
--1、查看所有存储过程与函数
exec sp_stored_procedures
或者
select * from dbo.sysobjects where OBJECTPROPERTY(id, N‘IsProcedure‘) = 1 order by name
--2、查看存储过程的内容
select text from syscomments where id=object_id(‘存储过程名称‘)
-- 或者用
sp_helptext 存储过程名称
--3、查看存储过程的参数情况
select ‘参数名称‘ = name,
‘类型‘ = type_name(xusertype),
‘长度‘ = length,
‘参数顺序‘ = colid,
‘排序方式‘ = collation
from syscolumns
where id=object_id(‘存储过程名称‘)
--或者
--查看存储过程参数信息:
--如果返回值>1,则有参数。否则无
CREATE PROC sp_PROC_Params
@procedure_name sysname , --存储过程或者用户定义函数名
@group_number int=1 , --存储过程的组号,必须在0到32767之间,0表示显示该存储过程组的所有参数
@operator nchar(2)=N‘=‘ --查找对象的运算符
AS
SET NOCOUNT ON
DECLARE @SQL nvarchar(4000)
SET @SQL=N‘SELECT
PorcedureName=CASE
WHEN o.xtype IN(‘‘P‘‘,‘‘X‘‘)
THEN QUOTENAME(o.name)+N‘‘;‘‘+CAST(c.number as varchar)
WHEN USER_NAME(o.uid)=‘‘system_function_schema‘‘
AND o.xtype=‘‘FN‘‘
THEN o.name
WHEN USER_NAME(o.uid)=‘‘system_function_schema‘‘
THEN ‘‘::‘‘+o.name
WHEN o.xtype=‘‘FN‘‘
THEN QUOTENAME(USER_NAME(o.uid))+N‘‘.‘‘+QUOTENAME(o.name)
ELSE QUOTENAME(o.name) END,
Owner=USER_NAME(o.uid),
GroupNumber=c.number,
ParamId=c.colid,
ParamName=CASE
WHEN o.xtype=‘‘FN‘‘ AND c.colid=0 THEN ‘‘<Returns>‘‘
ELSE c.name END,
Type=QUOTENAME(t.name)+CASE
WHEN t.name IN (‘‘decimal‘‘,‘‘numeric‘‘)
THEN N‘‘(‘‘+CAST(c.prec as varchar)+N‘‘,‘‘+CAST(c.scale as varchar)+N‘‘)‘‘
WHEN t.name=N‘‘float‘‘
OR t.name like ‘‘%char‘‘
OR t.name like ‘‘%binary‘‘
THEN N‘‘(‘‘+CAST(c.prec as varchar)+N‘‘)‘‘
ELSE ‘‘‘‘ END,
Orientation=CASE
WHEN o.xtype=‘‘FN‘‘ AND c.colid=0 THEN ‘‘<Returns>‘‘
ELSE N‘‘Input‘‘
+CASE WHEN c.isoutparam=1 THEN ‘‘/Output‘‘ ELSE ‘‘‘‘ END
END
FROM sysobjects o,syscolumns c,systypes t
WHERE o.id=c.id
AND c.xusertype=t.xusertype
AND o.name‘
+CASE WHEN @operator IN (‘=‘,‘>‘,‘>=‘,‘!>‘,‘<‘,‘<=‘,‘!<‘,‘<>‘,‘!=‘)
THEN @operator+QUOTENAME(@procedure_name,‘‘‘‘)
WHEN @operator=‘IN‘
THEN @operator+N‘ IN(‘+QUOTENAME(@procedure_name,‘‘‘‘)+‘)‘
WHEN @operator IN (‘LIKE‘,‘%‘)
THEN ‘ LIKE ‘+QUOTENAME(@procedure_name,‘‘‘‘)
ELSE ‘=‘+QUOTENAME(@procedure_name,‘‘‘‘)
END+N‘
AND((‘+CASE WHEN @group_number BETWEEN 1 AND 32767
THEN N‘c.number=‘+CAST(@group_number as varchar)
WHEN @group_number=0 THEN N‘1=1‘
ELSE N‘c.number=1‘
END+N‘ AND o.xtype IN(‘‘P‘‘,‘‘X‘‘))
OR (c.number=0 AND o.xtype=‘‘FN‘‘)
OR (c.number=1 AND o.xtype IN(‘‘IF‘‘,‘‘TF‘‘)))‘
EXEC sp_executesql @SQL
--4、查看所有存储过程内容
select b.name ,a.text from syscomments a,sysobjects b where object_id(b.name)=a.id and b.xtype in(‘P‘,‘TR‘)
--5、查看包含字符串内容的存储过程
select b.name ,a.text from syscomments a,sysobjects b
where
charindex(‘字符串内容‘,a.text)>0 and
object_id(b.name)=a.id and b.xtype in(‘P‘,‘TR‘)
SQL存储过程相关信息查看
标签:object 查看 user declare ima where 对象 方式 type
热心网友 时间:2022-05-03 04:39
怎么查询sql 存储过程里面的数据