tags:

views:

190

answers:

2

In trying to answer this question for myself I came across this nugget, after eventually adding "oracle" to my query terms:

select DBMS_METADATA.GET_DDL('TABLE','<table_name>') from DUAL;

Which works, but is not portable. How do I do the same thing on MySQL? SQLite? Others?

+1  A: 

Since database metadata isn't standardized, there's no standard way to do this.

S.Lott
That's unfortunate, and I should have realized if there was such a function to handle it in oracle, it's because a standard did not exist. Thanks!
Trevor Bramble
Unfortunate, but not entirely true - see my answer.
marc_s
+1  A: 

Well, there IS an ANSI standard called the INFORMATION_SCHEMA. Many vendors including Microsoft (SQL Server), Oracle, MySQL, Postgres support it, so that might be a first step.

For more information see this article here.

As for views, there's three INFORMATION_SCHEMA views for those:

  • INFORMATION_SCHEMA.VIEWS
  • INFORMATION_SCHEMA.VIEW_COLUMN_USAGE
  • INFORMATION_SCHEMA.VIEW_TABLE_USAGE

There is a column called "VIEW_DEFINITION" in the "INFORMATION_SCHEMA.VIEWS" view, so that would probably give you the information you need in a somewhat stadandized way.

Marc

marc_s
SQLite supports a thing like INFORMATION_SCHEMA. You, the user, define extra views with names like INFORMATION_SCHEMA_TABLES, which is not precisely the "standard". This post has a different opinion on the level of support: http://www.petefreitag.com/item/666.cfm
S.Lott