<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar.g?targetBlogID\x3d8211560\x26blogName\x3dTech+Tips,+Tricks+%26+Trivia\x26publishMode\x3dPUBLISH_MODE_BLOGSPOT\x26navbarType\x3dBLUE\x26layoutType\x3dCLASSIC\x26searchRoot\x3dhttp://mvark.blogspot.com/search\x26blogLocale\x3den\x26v\x3d2\x26homepageUrl\x3dhttp://mvark.blogspot.com/\x26vt\x3d-5147029996388199615', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe" }); } }); </script>

Tech Tips, Tricks & Trivia

by 'Anil' Radhakrishna
An architect's notes, experiments, discoveries and annotated bookmarks.

Search from over a hundred HOW TO articles, Tips and Tricks


HOW TO programatically find which tables are dependent on a specified table in SQL Server 2005

This was my take on the question that came up on a forum -

SELECT so.name
FROM sysobjects so INNER JOIN
sysreferences sr ON so.id = sr.rkeyid
WHERE (so.type = 'U') AND (sr.fkeyid = OBJECT_ID('employee'))

Replace the table name used in the OBJECT_ID function with the appropriate name

OBJECT_ID is a metadata (scalar) function that returns the database object identification number.
fkeyid column of sysreferences returns ID of the referencing table
rkeyid column of sysreferences returns ID of the referenced table
sysreferences system table contains mappings of FOREIGN KEY constraint definitions to the referenced columns.
sysobjects system table contains one row for each object (constraint, default, log, rule, stored procedure, and so on) created within a database. The type column specifies the Object type. We use 'U' to refer to a User table

The simpler way of course is to right-click the table in SQL Server 2005 Management Studio and click on View Dependencies. By default it shows, database objects that depend on the specified table and we can switch to the radio button option "Objects on which [table] depends" to view the dependent tables.

In SQL Server 2000, this can be accomplished by right-clicking a table in Enterprise Manager & then selecting "All Tasks" > "Diplay Dependencies...".

Labels: ,

Tweet this | Google+ it | Share on FB

« Home | Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »

»

Post a Comment