AlexCode Posted May 24, 2005 Posted May 24, 2005 Hi... I'm developing a tool that, using SQLDMO, retrieves the objects from the available SQL Servers. By now, I can retrieve anything but the relationships between tables!! How can I do that? Thanks! Alex :p Quote Software bugs are impossible to detect by anybody except the end user.
HJB417 Posted May 24, 2005 Posted May 24, 2005 relationships might be treated as a rule objects http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sqldmo/dmoref_ob_r_852s.asp Quote
AlexCode Posted May 24, 2005 Author Posted May 24, 2005 Hi... thanks for the reply but... If I connect to the Northwind DB, via SQLDMO, the Rules collection count = 0, but this DB have releationships between tables... :( Quote Software bugs are impossible to detect by anybody except the end user.
HJB417 Posted May 25, 2005 Posted May 25, 2005 static void OutputDbTableRelationships() { SQLServerClass sqlServer = new SQLServerClass(); sqlServer.LoginSecure = true; sqlServer.Connect("localhost", null, null); _Database db = sqlServer.Databases.Item("Northwind", null); foreach(_Table table in db.Tables) { foreach(Key key in table.Keys) { if(key.Type != SQLDMO_KEY_TYPE.SQLDMOKey_Foreign) continue; Console.WriteLine("{0}.{1} references {2}.{3}", table.Name, key.KeyColumns.Item(1), key.ReferencedTable, key.ReferencedColumns.Item(1)); } } } Quote
AlexCode Posted May 25, 2005 Author Posted May 25, 2005 Yeah... works!!! Thanks! Just to add... I had it donne calling a system sp: Dim result As SQLDMO.QueryResults = _ db.ExecuteWithResults("USE " & Me.m_DataBase.Name & " ; EXEC sp_helpconstraint '" & Tables(t).Name & "'") Thanks again. Alex :p Quote Software bugs are impossible to detect by anybody except the end user.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.