这种搜索不存在这样的系统表。而你可以根据你的目的尝试这个
DECLARE @ValueToSearch NVARCHAR(500)
DECLARE @SearchColumn NVARCHAR(100)
DECLARE @TableName NVARCHAR(200)
DECLARE @ColumnName NVARCHAR(200)
SET @ValueToSearch ='YOUR VALUE TP SEARCH'
SET @SearchColumn = 'YOUR COLUMN'
DECLARE @getResult CURSOR
SET @getResult = CURSOR FOR
SELECT t.name AS table_name,c.name AS column_name FROM sys.tables AS t INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID WHERE c.name = @SearchColumn
OPEN @getResult
FETCH NEXT FROM @getResult INTO @TableName,@ColumnName
WHILE @@FETCH_STATUS = 0
BEGIN
SET NOCOUNT ON ;
DECLARE @RESULT INT;
DECLARE @TYPE INT
DECLARE @QUERY NVARCHAR(1000)
SET @QUERY = 'select @RESULT=count(*) from ' + ISNULL(@TableName,'') +' WHERE '+ ISNULL(@ColumnName,'')+'='''+ ISNULL(@ValueToSearch,'') +''''
EXEC sp_executesql @QUERY,
N'@result int OUTPUT, @type int OUTPUT',
@RESULT OUTPUT,
@TYPE OUTPUT
IF(ISNULL(@RESULT,0)>0)
BEGIN
SET NOCOUNT ON;
SELECT ' COLUMN '+ @ColumnName + ' OF TABLE ' +@TableName+ ' HAS THIS VALUE.'
END
FETCH NEXT FROM @getResult INTO @TableName,@ColumnName
END
CLOSE @getResult
DEALLOCATE @getResult
谢谢
马诺伊