SQL help - find the table that has 'somefieldId' as the primary key?

Posted by Kettenbach on Stack Overflow See other posts from Stack Overflow or by Kettenbach
Published on 2010-05-13T17:31:09Z Indexed on 2010/05/13 17:34 UTC
Read the original article Hit count: 252

Filed under:
|
|
|

Hello All, How can I search my sql database for a table that contains a field 'tiEntityId'. This field is referenced in a stored procedure, but I am unable to identify which table this id is a primary key for? Any suggestions? I currently look through stored procedure definitions for references to text by using something like this

Declare @Search varchar(255)
SET @Search='[10.10.100.50]'

SELECT DISTINCT
o.name AS Object_Name,o.type_desc
FROM sys.sql_modules        m 
    INNER JOIN sys.objects  o ON m.object_id=o.object_id
WHERE m.definition Like '%'+@Search+'%'
ORDER BY 2,1

Any SQL guru's out there know what I need to use to find the table that contains the field, 'preferably the table where that field is the Primary Key.

Thanks so much for any tips. Cheers, ~ck in San Diego

© Stack Overflow or respective owner

Related posts about sql-server

Related posts about search