展开全部
CREATEPROCEDUREFindString(@ValueVARCHAR(1024))AS
BEGIN
SETNOCOUNTON;
DECLARE@SQLVARCHAR(6000)
DECLARE@TableVARCHAR(100)
DECLARE@ColumnVARCHAR(100)
CREATETABLE#T(TableNameVARCHAR(100),ColumnNameVARCHAR(100))
DECLARETABLESCURSORFORSELECTO.name,C.nameFROMsys.syscolumnsCINNERJOINsys.sysobjectsOONC.id=O.id
WHEREO.type='U'ANDC.xtypeIN(167,175,231,239)ORDERBYO.name,C.name
OPENTABLES
FETCHNEXTFROMTABLESINTO@Table,@Column
WHILE@@FETCH_STATUS=0
BEGIN
SET@SQL='IFEXISTS(SELECTNULLFROM['+@Table+']WHERERTRIM(LTRIM(['+@Column+']))LIKE''%'+@Value+'%'')'
SET@SQL=@SQL+'INSERTINTO#TVALUES('''+@Table+''','''+@Column+''')'
EXEC(@SQL)
FETCHNEXTFROMTABLESINTO@Table,@Column
END
CLOSETABLES
DEALLOCATETABLES
SELECT*FROM#T
DROPTABLE#T
End
调用方法:
EXEC FindString '查找的32313133353236313431303231363533e78988e69d8331333337373733字符串'
如果觉得《mysql查询表中名字包含某个字符_查询当前数据库中所有用户表中哪些字段包含某个字符串...》对你有帮助,请点赞、收藏,并留下你的观点哦!