问题
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