Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 column dependencies

Author  Topic 

jim_jim
Constraint Violating Yak Guru

306 Posts

Posted - 2010-08-17 : 12:41:15
Hi
I know we can see the dependencies of a table,sp etc

I want to know whether we have a way to identify dependencies based on a particular column.I mean what all tables,views,sp are dependent on a column

X002548
Not Just a Number

15586 Posts

Posted - 2010-08-17 : 12:54:59
Sorry it doesn't work that way..doesn't mean we can't build a hack



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-08-17 : 13:00:13
no direct method. you can however query catalog views to get this information.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-08-17 : 13:10:19
...like...



SELECT DISTINCT 'TABLES' AS OBJECT, t.TABLE_TYPE AS OBJECT_TYPE, t.TABLE_NAME AS [OBJECT_NAME]
FROM INFORMATION_SCHEMA.Columns c INNER JOIN INFORMATION_SCHEMA.Tables t
ON t.TABLE_CATALOG = c.TABLE_CATALOG AND t.TABLE_SCHEMA = c.TABLE_SCHEMA AND t.TABLE_NAME = c.TABLE_NAME
WHERE COLUMN_NAME IN ('acct_ledger', 'acct_num')
UNION
SELECT DISTINCT 'ROUTINES' AS OBJECT, ROUTINE_TYPE AS OBJECT_TYPE, ROUTINE_NAME AS [OBJECT_NAME]
FROM INFORMATION_SCHEMA.Routines
WHERE ROUTINE_DEFINITION LIKE '%acct_ledger%'
OR ROUTINE_DEFINITION LIKE '%acct_num%'





Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

jim_jim
Constraint Violating Yak Guru

306 Posts

Posted - 2010-08-17 : 13:18:09
uhhhhhh
It will take sometime for me to digest the above code and use it for our environment

Thanks Bret my freind and Visakh

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-08-17 : 13:24:52
quote:
Originally posted by X002548

...like...



SELECT DISTINCT 'TABLES' AS OBJECT, t.TABLE_TYPE AS OBJECT_TYPE, t.TABLE_NAME AS [OBJECT_NAME]
FROM INFORMATION_SCHEMA.Columns c INNER JOIN INFORMATION_SCHEMA.Tables t
ON t.TABLE_CATALOG = c.TABLE_CATALOG AND t.TABLE_SCHEMA = c.TABLE_SCHEMA AND t.TABLE_NAME = c.TABLE_NAME
WHERE COLUMN_NAME IN ('acct_ledger', 'acct_num')
UNION
SELECT DISTINCT 'ROUTINES' AS OBJECT, ROUTINE_TYPE AS OBJECT_TYPE, ROUTINE_NAME AS [OBJECT_NAME]
FROM INFORMATION_SCHEMA.Routines
WHERE ROUTINE_DEFINITION LIKE '%acct_ledger%'
OR ROUTINE_DEFINITION LIKE '%acct_num%'





Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam






What if routine definition goes beyond 4000 chars. hence i would prefer below


SELECT OBJECT_NAME(m.object_id) AS Name,m.definition
FROM sys.sql_modules m
INNER JOIN sys.objects o
ON o.object_id = m.object_id

WHERE m.definition like '%column name here%'
AND o.type='P'

if you want to look specifically for procedures add code in green also

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-08-17 : 13:35:00
hmmm....even in DB2 if it goes over, they give you n number of rows to complete the definition...

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -