작성일 : 12-11-15 10:38
|
[MsSQL] MSSQL 특정 컬럼명을 포함한 테이블 찾기
|
|
|
글쓴이 :
조형래
 조회 : 4,675
|
/*
Declare @column_name varchar(20)
Select @column_name = 'user_id'
Select Table_name from information_schema.columns
where column_name=@column_name
*/
Declare @column_name varchar(20)
Select @column_name = 'user_id'
declare @i int
declare @count int
declare @tmp_sql varchar(max)
declare @tmp_table table (i int, column_name varchar(max))
insert into @tmp_table
Select
row_number() over (order by column_name) as 'i',
'select * from ' + Table_name + ' where user_id = ''C_realheart''' as 'column_name'
from information_schema.columns where column_name = @column_name
Select @count = count(*) from @tmp_table
set @i = 1
while (@i <= @count)
BEGIN
SELECT @tmp_sql = column_name FROM @tmp_table where i = @i
SET @i = @i + 1
print @tmp_sql
END
|
|