开发者

Utility to create sql statements

This is a question about Sql generation, not sql creating sql nor ORM.

Is their any cross database tools that will enable the creation of insert statements, e.g. for all the tables in particular schema or namespace. Say the namespace/schema is Aqua in Sql Server 2008, and your utility comes along and generates all possible insert statements for that namespace/sche开发者_开发百科ma. And it works on Oracle/MySql/Postgres/db2 etc.

Thanks. Bob


ANSI SQL provides for a standard set of views under the schema INFORMATION_SCHEMA to provide metadata for just this purpose.

For generating simple table insert statement templates, all the information you really need to generate an insert statement for a given table is to execute this query:

select *
from INFORMATION_SCHEMA.COLUMNS
where TABLE_CATALOG = <my-db-name>
  and TABLE_SCHEMA  = <table-owner-schema>
  and TABLE_NAME    = <table-name>
order by ORDINAL_POSITION

in any database that supports the ANSI information schema views. That will give you one row for every column in the specified table, in the expected sequence.

Outside of the above, since no two vendors support the set of system tables with metadata, your pretty much SOL for a cross-database solution. And sadly, I don't believe the Oracle supports the ANSI information schema views.

Though you might look at Red Gate's product family: http://www.red-gate.com/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜