I am currently working on a project that requires fetching database schema through an ODBC connection. Mainly because the source could be an Access database, SQL Ser开发者_JS百科ver, Oracle, etc. With this I will recreate the customers schema into a SQL Database.
Everything is working fine, but I am not able to find a way to retrieve the relationships between tables and I could not find anything on MSDN about this. If this cannot be done then I need to know another generic way of doing it.
Thanks in advance for any answers.
If you are using the ODBC API directly, the API SQLForeignKeys can be used for this. However, since you are using OdbcConnection objects, it would be a painful process to use the API for this one task. Well, for that matter, using the ODBC API directly for anything is a lot of work.
Edit I suggested the possibility of using OdbcConnectionGetSchema with 'ForeignKeys'
as the collection name. However, I looked into that and, unfortunately, OdbcConnection does not appear to support that collection.
So aside from using SQLForeignKeys directly (or making database-specific calls), it seems that ODBC is not going to provide an easy route to gather that information generically. If someone can provide an answer with a nice mechanism for doing it, I will delete this answer since its only value at this point is to point out that I don't know how to find the information cleanly.
精彩评论