Answers:
嗯,您可以尝试:
use <your_database>
select o.name,c.name
from sys.columns c inner join sys.objects o on c.object_id=o.object_id
and o.type = 'U'
and CHARINDEX('<your_sub_string>', c.name)>=1
USE <database>;
Declare @Col varchar(10);
Declare @Val varchar(10);
Declare @tablename varchar(20);
Declare @sql nvarchar(200);
Declare @sql1 nvarchar(200);
SET @Col = '...'; --INSERT COLUMN NAME
SET @Val = ...; -- INSERT COLUMN VALUE
IF OBJECT_ID('tempdb.dbo.##TempTable1', 'U') IS NOT NULL
DROP TABLE ##TempTable1;
SELECT NULL AS MYKEY, name
into ##TempTable1
FROM sysobjects
WHERE id IN ( SELECT id FROM syscolumns WHERE name = @Col )
ORDER BY name asc
set rowcount 1
update ##TempTable1 set mykey = 1
while @@rowcount > 0
begin
set rowcount 0
set @tablename = (select name from ##TempTable1 where mykey = 1)
set @sql = 'If Exists (SELECT * FROM '+@tablename+' WHERE '+@Col+'='+@Val+') SELECT * FROM '+@tablename+' WHERE '+@Col+'='+@Val+';'
set @sql1 = 'If Exists (SELECT * FROM '+@tablename+' WHERE '+@Col+'='+@Val+') select name from ##TempTable1 where mykey = 1'
EXEC sp_executesql @sql1
EXEC sp_executesql @sql
delete ##TempTable1 where mykey = 1
set rowcount 1
update ##TempTable1 set mykey = 1
end
set rowcount 0