SQLProNews This is an iEntry Publication

Advertising, Headlines, Signup
SQLProNews
SecurityProNews
ITmanagement











The Latest Internet News
Add Headlines for your site


INFORMATION_SCHEMA Support In MySQL, PostgreSQL

By Pete Freitag
Expert Author
Article Date: 2008-02-18

I've known about the INFORMATION_SCHEMA views (or system tables) in SQL Server for a while, but I just leared recently that they are actually part of the SQL-92 standard and supported on other database platforms.

The INFORMATION_SCHEMA views provide meta data information about the tables, columns, and other parts of your database. Because the structure of these tables are standardized you can write SQL statements that work on various database platforms.

For example suppose you want to return a resultset with a list of all columns in a table called employees

SELECT table_name, column_name, is_nullable, data_type, character_maximum_length
FROM INFORMATION_SCHEMA.Columns
WHERE table_name = 'employees'


Quite a handy feature, but it's hard to find what versions the of various database platforms started supporting this feature, here's a quick list:
    Microsoft SQL Server - Supported in Version 7 and up
    MySQL - Supported in Version 5 and up
    PostgreSQL - Supported in Version 7.4 and up
    Oracle - Does not appear to be supported
    Apache Derby - NOT Supported As of Version 10.3
I have been using the INFORMATION_SCHEMA views to build some automatic datatype validation. With the INFORMATION_SCHEMA you can get the datatype, max character length, and if null values are allowed, and perform validation before it hits the database. And if a column is made wider, you don't have to make any code changes.

Ofcourse if you are using ColdFusion 8, you can use the new cfdbinfo tag to get the same column information. The cfdbinfo actually uses the JDBC Driver's getMetaData() method (this is part of the JDBC Standard that Drivers implement this method). Apache Derby doesn't support the INFORMATION_SCHEMA views because they prefer to simply implement the JDBC Driver's getMetaData() method.

Here's a list of the information schema views:
    • INFORMATION_SCHEMA.SCHEMATA
    • INFORMATION_SCHEMA.TABLES
    • INFORMATION_SCHEMA.COLUMNS
    • INFORMATION_SCHEMA.STATISTICS
    • INFORMATION_SCHEMA.USER_PRIVILEGES
    • INFORMATION_SCHEMA.SCHEMA_PRIVILEGES
    • INFORMATION_SCHEMA.TABLE_PRIVILEGES
    • INFORMATION_SCHEMA.COLUMN_PRIVILEGES
    • INFORMATION_SCHEMA.CHARACTER_SETS
    • INFORMATION_SCHEMA.COLLATIONS
    • INFORMATION_SCHEMA.COLLATION_CHARACTER_SET_APPLICABILITY
    • INFORMATION_SCHEMA.TABLE_CONSTRAINTS
    • INFORMATION_SCHEMA.KEY_COLUMN_USAGE
    • INFORMATION_SCHEMA.ROUTINES
    • INFORMATION_SCHEMA.VIEWS
    • INFORMATION_SCHEMA.TRIGGERS
    • INFORMATION_SCHEMA.PROFILING
Comments

Originally published at petefreitag.com


About the Author:
Pete Freitag (http://www.petefreitag.com/) is a software engineer, and web developer located in central new york. Pete specializes in the HTTP protocol, web services, xml, java, and coldfusion. In 2003 Pete published the ColdFusion MX Developers Cookbook with SAMs Publishing.

Pete owns a Firm called Foundeo (http://foundeo.com/) that specializes in Web Consulting, and Products for Web Developers.




SQLProNews is an iEntry, Inc. ® publication - 1998-2008 All Rights Reserved Privacy Policy and Legal
INFORMATION SCHEMA Support in MySQL PostgreSQL