ITPub博客

首页 > 数据库 > Oracle > Script: To list Foreign Key Constraints (Doc ID 1039297.6)

Script: To list Foreign Key Constraints (Doc ID 1039297.6)

Oracle 作者:rongshiyuan 时间:2014-03-24 12:09:39 0 删除 编辑
Script: To list Foreign Key Constraints (Doc ID 1039297.6)

@***Checked for relevance on 26-Jun-2012***
?
Abstract
This script will list foreign key constraints for a particular table.
?

Product Name, Product Version

Oracle Server, 7.3.4 to 9.2.0
Platform Platform Independent
Date Created 7-Sep-1999
?
Instructions
Execution Environment:
     SQL, SQL*Plus

Access Privileges:
     Requires DBA access privileges to be executed.

Usage:
     sqlplus user/

Instructions:
     Copy the script to a file and execute it from SQL*Plus.

PROOFREAD THIS SCRIPT BEFORE USING IT! Due to differences in the way text 
editors, e-mail packages, and operating systems handle text formatting (spaces, 
tabs, and carriage returns), this script may not be in an executable state
when you first receive it. Check over the script to ensure that errors of
this type are corrected.
?
Description
When referential integrity is enforced, to perform data loading or massive  
deletes, it is useful or sometimes necessary to disable the foreign key  
constraints.  
 
You need to disable the foreign keys to load large amounts of data via 
SQL*Loader, Import or SQL script.  The following is a sample script to list 
foreign key(s) for a particular table. 
?
References
 ?
?
Script
rem **************************************************************** 
rem 
rem If necessary, reformat the columns to avoid column wrapping. 
rem 
rem Change the table name USER_CONSTRAINTS to ALL_CONSTRAINTS or  
rem DBA_CONSTRAINTS to change the scope of the query.  
rem 
rem To list the reference on a particular table only, add the table 
rem name to the WHERE clause, i.e., 
rem  
rem    AND A.TABLE_NAME = &tbl_name 
rem 
rem **************************************************************** 
 
column table_name         format a20 
column key_name           format a14 
column referencing_table  format a20 
column foreign_key_name   format a14 
column fk_status          format a8 
 
set linesize 80 
set pagesize 0 
set tab      off 
set space    1 
 
SELECT  
    A.TABLE_NAME table_name, 
    A.CONSTRAINT_NAME key_name, 
    B.TABLE_NAME referencing_table, 
    B.CONSTRAINT_NAME foreign_key_name, 
    B.STATUS fk_status  
  FROM USER_CONSTRAINTS A, USER_CONSTRAINTS B  
  WHERE 
    A.CONSTRAINT_NAME = B.R_CONSTRAINT_NAME and 
    B.CONSTRAINT_TYPE = 'R' 
  ORDER BY 1, 2, 3, 4;
  

==============
Sample Output:
==============

SQL> @savedscript
DEPT                 PK_DEPT        EMP                  FK_DEPTNO      ENABLED
ENTITY               SYS_C0013659   ENTITY_REVISION      SYS_C0013665   ENABLE
?
?
Disclaimer
EXCEPT WHERE EXPRESSLY PROVIDED OTHERWISE, THE INFORMATION, SOFTWARE,
PROVIDED ON AN "AS IS" AND "AS AVAILABLE" BASIS. ORACLE EXPRESSLY DISCLAIMS
ALL WARRANTIES OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NON-INFRINGEMENT. ORACLE MAKES NO WARRANTY THAT: (A) THE RESULTS
THAT MAY BE OBTAINED FROM THE USE OF THE SOFTWARE WILL BE ACCURATE OR
RELIABLE; OR (B) THE INFORMATION, OR OTHER MATERIAL OBTAINED WILL MEET YOUR
EXPECTATIONS. ANY CONTENT, MATERIALS, INFORMATION OR SOFTWARE DOWNLOADED OR
OTHERWISE OBTAINED IS DONE AT YOUR OWN DISCRETION AND RISK. ORACLE SHALL HAVE
NO RESPONSIBILITY FOR ANY DAMAGE TO YOUR COMPUTER SYSTEM OR LOSS OF DATA THAT
RESULTS FROM THE DOWNLOAD OF ANY CONTENT, MATERIALS, INFORMATION OR SOFTWARE.

ORACLE RESERVES THE RIGHT TO MAKE CHANGES OR UPDATES TO THE SOFTWARE AT ANY
TIME WITHOUT NOTICE.
?
Limitation of Liability
IN NO EVENT SHALL ORACLE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL OR CONSEQUENTIAL DAMAGES, OR DAMAGES FOR LOSS OF PROFITS, REVENUE,
DATA OR USE, INCURRED BY YOU OR ANY THIRD PARTY, WHETHER IN AN ACTION IN
CONTRACT OR TORT, ARISING FROM YOUR ACCESS TO, OR USE OF, THE SOFTWARE.

SOME JURISDICTIONS DO NOT ALLOW THE LIMITATION OR EXCLUSION OF LIABILITY.
ACCORDINGLY, SOME OF THE ABOVE LIMITATIONS MAY NOT APPLY TO YOU.
?
?

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/17252115/viewspace-1128187/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2009-11-24

  • 博文量
    798
  • 访问量
    3251145