代码改变世界

如何查询数据库外键参考的schema:

2007-02-05 09:26  爱车龟速兔  阅读(353)  评论(0编辑  收藏  举报

select

   referent.constraint_name as fk_name,

   referent.update_rule,

   referent.delete_rule,

   kcol_usage.table_name as fk_table_name,

   kcol_usage.column_name as fk_column_name,

   kcol_usage1.table_name as pk_table_name,

   kcol_usage1.column_name as pk_column_name

from

   INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS referent

   join INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcol_usage

      on (referent.constraint_name = kcol_usage.constraint_name) join INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcol_usage1 on (referent.unique_constraint_name = kcol_usage1.constraint_name)