<p>I am writing a DDL script to drop a number of tables but need to identify all dependencies for those tables first. Those dependencies include foreign key constraints, stored procedures, views, etc. Preferably, I want to programmatically script out dropping those dependencies using the system tables/views before dropping the dependent table.</p>

[{'answer_id': 53092, 'author': 'Almond', 'author_id': 1603, 'author_profile': 'https://Stackoverflow.com/users/1603', 'pm_score': -1, 'selected': False, 'text': '<p>You can use the sp_depends stored procedure to do this:</p>\n\n<p><code>USE AdventureWorks\nGO\nEXEC sp_depends @objname = N\'Sales.Customer\' ;</code></p>\n\n<p><a href="http://msdn.microsoft.com/en-us/library/ms189487(SQL.90).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms189487(SQL.90).aspx</a></p>\n'}, {'answer_id': 53099, 'author': 'SQLMenace', 'author_id': 740, 'author_profile': 'https://Stackoverflow.com/users/740', 'pm_score': 1, 'selected': False, 'text': '<p>sp_depends is not reliable see: <a href="http://sqlblog.com/blogs/denis_gobo/archive/2008/05/06/6653.aspx" rel="nofollow noreferrer">Do you depend on sp_depends (no pun intended)</a></p>\n'}, {'answer_id': 53105, 'author': 'Eric', 'author_id': 4540, 'author_profile': 'https://Stackoverflow.com/users/4540', 'pm_score': 2, 'selected': False, 'text': '<p>This is extremely messy to write from scratch.  Have you considered a 3rd party tool like\n<a href="http://www.red-gate.com/products/SQL_Dependency_Tracker/index.htm" rel="nofollow noreferrer" title="Red-Gate SQL Dependency Tracker">Red-Gate SQL Dependency Tracker</a>?</p>\n'}, {'answer_id': 53111, 'author': 'Mauro', 'author_id': 2208, 'author_profile': 'https://Stackoverflow.com/users/2208', 'pm_score': 0, 'selected': False, 'text': '<p>you could always search through the syscomments table....that might take a while though...</p>\n'}, {'answer_id': 1010628, 'author': 'glasnt', 'author_id': 124019, 'author_profile': 'https://Stackoverflow.com/users/124019', 'pm_score': 0, 'selected': False, 'text': "<p>Could you reference <code>sysreferences</code>?</p>\n\n<pre><code>select 'if exists (select name from sysobjects where name = '''+c.name+''') '\n+' alter table ' + t.name +' drop constraint '+ c.name \n from sysreferences sbr, sysobjects c, sysobjects t, sysobjects r\n where c.id = constrid \n  and t.id = tableid \n  and reftabid = r.id\n  and r.name = 'my_table'\n</code></pre>\n\n<p>That will generate a whole lot of conditional <code>drop constraint</code> calls. Should work.</p>\n"}]
['https://Stackoverflow.com/questions/53069', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4872/']