Q:

how can i get name of table and its column while checking the reference of any value in multiple columns?

When deleting any Team from team table, i need to check that teamId is available in other tables or not. for this i am using following query:-
        select  count(TeamId) from 
        ( select TeamId from Project union all 
          select  TeamId from TeamMember union all 
          select  TeamId from Department union all 
          select TeamId from Role   union all 
        ) as Id where TeamId = 1

this query is working fine, and returns number of count. 
but now i need name of that table and its column, where i found that teamId. 
if it is possible than please give me right solution.
thanks in advance..

A:

 select 'Project' tableName from Project
 where TeamId = 1
 union all 
 select 'TeamMember' from TeamMember
 where TeamId = 1
 union all 
 select 'Department' from Department
 where TeamId = 1
 union all 
 select 'Role' from Role
 where TeamId = 1

I don't see why you need the "column" where it was found, since in all cases you listed "TeamId".  If it were named different things in different tables instead, then you could use this:
 select 'Project' tableName, 'TeamId' columnName from Project
 where TeamId = 1
 union all 
 select 'TeamMember', 'Member_TeamId' from TeamMember
 where Member_TeamId = 1

And finally, if you wanted the "row" (record) instead, you can add the ID into the column:
 select 'Project' tableName, ProjectID idInTable from Project
 where TeamId = 1
 union all 
 select 'TeamMember', TeamMemberId from TeamMember
 where TeamId = 1

