SQL Server: should I use information_schema tables over sys tables?
Solution 1:
Unless you are writing an application which you know for a fact will need to be portable or you only want quite basic information I would just default to using the proprietary SQL Server system views to begin with.
The Information_Schema
views only show objects that are compatible with the SQL-92 standard. This means there is no information schema view for even quite basic constructs such as indexes (These are not defined in the standard and are left as implementation details.) Let alone any SQL Server proprietary features.
Additionally it is not quite the panacea for portability that one may assume. Implementations do still differ between systems. Oracle does not implement it "out of the box" at all and the MySql docs say:
Users of SQL Server 2000 (which also follows the standard) may notice a strong similarity. However, MySQL has omitted many columns that are not relevant for our implementation, and added columns that are MySQL-specific. One such column is the ENGINE column in the INFORMATION_SCHEMA.TABLES table.
Even for bread and butter SQL constructs such as foreign key constraints the Information_Schema
views can be dramatically less efficient to work with than the sys.
views as they do not expose object ids that would allow efficient querying.
e.g. See the question SQL query slow-down from 1 second to 11 minutes - why? and execution plans.
INFORMATION_SCHEMA
sys
Solution 2:
I would always try to use the Information_schema
views over querying the sys
schema directly.
The Views are ISO compliant so in theory you should be able to easily migrate any queries across different RDBMS.
However, there have been some cases where the information that I need is just not available in a view.
I've provided some links with further information on the views and querying a SQL Server Catalog.
http://msdn.microsoft.com/en-us/library/ms186778.aspx
http://msdn.microsoft.com/en-us/library/ms189082.aspx