Querying database schema of SQL Server DB via ODBC?

眉间皱痕 提交于 2019-12-22 17:58:52

问题


Is there a generic way to retrieve a database schema using ODBC that works across databases?

If not, what is the easiest way to do this when the database server is MS SQL Server?

I am working with unixodbc, from Linux.


回答1:


Query against the INFORMATION_SCHEMA views. Beautiful thing about using information schema is that it's a standard so it should be portable to any database that has implemented the standard.

e.g. SELECT * FROM INFORMATION_SCHEMA.COLUMNS ISC

The standard is the SQL-92 Starts at page 535




回答2:


If you want to get a list of the schema's in the database, you can use the wildcard in the SQLTables call

SQLTables( stmt, NULL, 0, "%", SQL_NTS, NULL, 0, NULL, 0 );

Or something close to that.



来源:https://stackoverflow.com/questions/7955718/querying-database-schema-of-sql-server-db-via-odbc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!