ODBC 架构 - 如何查找关系?
我目前正在开发一个需要通过 ODBC 连接获取数据库架构的项目。主要是因为源可能是 Access 数据库、SQL Server、Oracle 等。 这样,我将把客户模式重新创建到 SQL 数据库中。
一切工作正常,但我无法找到一种方法来检索表之间的关系,并且我在 MSDN 上找不到任何与此相关的内容。如果这不能做到,那么我需要知道另一种通用方法。
预先感谢您的任何答复。
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 Server, 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您直接使用 ODBC API,则 API SQLForeignKeys 可用于此目的。但是,由于您使用的是 OdbcConnection 对象,因此使用 API 来完成此任务将是一个痛苦的过程。就这一点而言,直接使用 ODBC API 进行任何操作都是一项繁重的工作。
编辑我建议使用OdbcConnectionGetSchema的可能性以
'ForeignKeys'
作为集合名称。但是,我对此进行了调查,不幸的是,OdbcConnection 似乎不支持该集合。因此,除了直接使用 SQLForeignKeys(或进行特定于数据库的调用)之外,ODBC 似乎不会提供一种简单的途径来收集一般信息。如果有人可以提供一个具有良好机制的答案,我将删除这个答案,因为它此时唯一的价值是指出我不知道如何干净地找到信息。
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.