Newsletter Subscription | Glossary | Contact Us
Home > All Categories > PostgreSQL > Data Dictionary > INFORMATION_SCHEMA Support in MySQL, PostgreSQL
Question Title INFORMATION_SCHEMA Support in MySQL, PostgreSQL
Authored by: Thomas Darwin
Viewed: 360 times so far

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

Source :petefreitag.com
Click Here to View all the questions in Data Dictionary category.
File Attachments File Attachments
There are no attachment file(s) related to this question.
User Comments User Comments
There are no user comments for this question. Be the first to post a comment. Click Here
Post Comment Add a Comment
Email Address:
Comment/Message
Verify Code

Post Comment How helpful was this article to you?
Related Questions Related Article
There are no other questions related to this question.
Article Information Additional Information
Article Number: 104
Created: 2008-02-18 5:16 PM
Rating No Rating
 
Article Options Article Options
Print Question Print this Question/Article
Email Question Email this Question/Article to Friend
Export to MS Word Export to MS Word
Bookmark Article
del.icio.us Bookmark del.icio.us Bookmark
Digg It Digg It
Furl It Furl It
Subscribe to Article Subscribe to Article
 
Language Translation Language Translation
 
Search Knowledge Base Search Knowledge Base