sql - How to find table names which have a same value in other tables based aone column -
i have database many tables , table has common column. how can retrieve table have same value in column?
ex:- have 25 table, tables have column name ccode
want know tables have same value column?
the following statement create union select brings data need in 1 result set. best set query output text , don't forget set query option max text highest (8192). take result of select new sql window , execute it:
alltableswithmycolumn ( select distinct table_name information_schema.columns column_name='ccode' ) select stuff( ( select 'union select ''' + table_name + ''' tablename, ccode ' + table_name + char(13) + char(10) alltableswithmycolumn xml path(''),type ).value('.','varchar(max)'),1,6,'')
if need further help, tell me...
Comments
Post a Comment