SQL Server 查找文本字符串的SQL SP的名称是什么?

qmelpv7a  于 2023-01-25  发布在  其他
关注(0)|答案(3)|浏览(121)

我很尴尬,但我不记得MS SQL Server SP的名称,它搜索您的数据库中指定的文本字符串,并返回所有包含该字符串的表名,函数,存储过程等。我不能在帮助中查找它,因为为了获得帮助,你需要知道它的名称!它是类似sp_findtext的东西。
它叫什么名字?
来吧,最快的手指得到答案学分!:)

iqxoj9l9

iqxoj9l91#

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=32319开始

CREATE PROCEDURE sp_FindText @text varchar(8000), @findtype varchar(1)='P' AS
SET NOCOUNT ON
IF @findtype='P' SELECT DISTINCT Len(SubString(text,1, PatIndex('%' + @text + '%', text)))-Len(Replace(SubString(text,1, PatIndex('%' + @text + '%', text)),char(13),''))+1 AS Line,
--PatIndex('%' + @text + '%', text) AS Position,
OBJECT_NAME(id) AS ProcName
FROM syscomments
WHERE text like '%' + @text + '%'
ORDER BY ProcName, Line

IF @findtype='C' EXEC('SELECT TABLE_NAME + ''.'' + COLUMN_NAME AS TableColumn FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME LIKE ''%' + @text + '%'' ORDER BY TableColumn')

IF @findtype='T' EXEC('SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE ''%' + @text + '%'' ORDER BY TABLE_NAME')
GO

它不仅搜索过程和视图定义文本,还将查找表、视图和列名:

EXEC sp_FindText 'myTable' --or-- EXEC sp_FindText 'myTable', 'P' --finds procedures/views containing 'myTable' in their definition/code
EXEC sp_FindText 'myTable', 'T' --finds tables/views containing 'myTable' in their name
EXEC sp_FindText 'myCol', 'C' --finds columns containing 'myCol' in their name
yfjy0ee7

yfjy0ee72#

我找到了一个自定义SP(FindTextInDatabase),它可以做到这一点:
Link
也不知道有没有现成的程序,有也找不到。

ddhy6vgd

ddhy6vgd3#

快速检查以下各项的结果:

select * from sysobjects where [name] like 'sp_%' order by 1
select * from master..sysobjects where [name] like 'sp_%' order by 1

你找到适合你的东西。
干杯!

相关问题