0

Using Visual Studio 2010 & SQL Server 2008. There's a field in a table that I'm looking into. Not sure if it's even being used anywhere or if it is being used, how it's being used.

Any easy way to tell what vb/c# code files in my solution or stored procs are using this field. I know I could simply do a "edit/find" and use the field name. But didn't know if there was an easier, better, or more thorough way to check? Thanks!

WebDevGuy
  • 173
  • 4
  • 18
  • Change the name of the column and see if anything "breaks"? – Dave Mason Mar 20 '14 at 17:30
  • Have you seen [Determine Which Objects Reference a Table in SQL Server](http://stackoverflow.com/questions/13563364/determine-which-objects-reference-a-table-in-sql-server)?? – huMpty duMpty Mar 20 '14 at 17:33
  • @huMptyduMpty - that question seems to be only about DB internal references to the field (view, SSPS etc). This question is about external references. – Hogan Mar 20 '14 at 17:35
  • In @huMptyduMpty's defense, you really need to be concerned with both internal and external. Externally, something may reference the column indirectly (ie stored proc, view, user-defined function, etc.). – Dave Mason Mar 20 '14 at 17:39
  • @DMason - You are correct, of course -- but the question clearly asks about external code (vb/c#) and it would a real shame this question was closed as a duplicate of a question which about something totally different. – Hogan Mar 20 '14 at 18:18
  • @Hogan: I suppose we are interpreting the OP's question differently. My take is the VS code files are external and stored procs are internal. The OP inquired about both. – Dave Mason Mar 20 '14 at 18:27
  • 1
    Thanks for all the comments and input. Yes, my question was about finding out if this field is used anywhere, within SQL server (stored procs) or my Visual Studio solution (containing both VB.NET and C# code). – WebDevGuy Mar 20 '14 at 20:21

1 Answers1

1

@DMason suggested you "Change the name of the column and see if anything "breaks"?" I don't recommend this because it involves breaking your system. However, you could set up triggers on the table which write to an audit table whenever it is accessed, let the system run for a while and see what accessed it.

Not a perfect solution and it would be much better if your system had some good documentation (eg a Data Dictionary by definition would tell you where it was being used), however it will work.

If you can't use a trigger you could also do a grep for the field name on ALL of your source. Then review the results by hand to see where it is used, if anywhere. I do not suggest you use VS internal find because this will skip certain files -- use an external grep.

Hogan
  • 69,564
  • 10
  • 76
  • 117