发布时间:2019-11-14编辑:佚名阅读(2555)
SELECT CONVERT(VARCHAR(255), '') dsca INTO #y WHERE 1 = 0; -- delete #y DECLARE @s VARCHAR(255); SET @s = '搜索字符串'; DECLARE bbb CURSOR FOR SELECT TABLE_NAME, column_name FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name IN (SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_type = 'BASE TABLE' AND table_name LIKE '%%') AND data_type LIKE '%varchar%'; DECLARE @t VARCHAR(255); DECLARE @f VARCHAR(255); OPEN bbb; FETCH NEXT FROM bbb INTO @t, @f; WHILE @@fetch_status = 0 BEGIN EXEC (' if exists (select * from ' + @t + ' where ' + @f + '=' + '''' + @s + '''' + ' ) insert into #y select ' + '''' + @t + '.' + @f + ''''); --insert into #t select '+''''+'select * from '+@t+' WHERE '+@f+'=@F'+''' FETCH NEXT FROM bbb INTO @t, @f; END; CLOSE bbb; DEALLOCATE bbb; SELECT * FROM #y; DROP TABLE #y;
关键字: sql server 数据库 所有表 查找某字符串
0人
0人
0人
0人