Skip to content

约束索引查询

Xugu、Oracle查看某个表的索引信息:

  • Oracle:
    sql
    SQL> SELECT TABLE_OWNER,TABLE_NAME,INDEX_NAME FROM USER_INDEXES WHERE TABLE_NAME=UPPER('table_name');
  • Xugu:
    sql
    SQL> SELECT S.SCHEMA_NAME,T.TABLE_NAME,I.INDEX_NAME FROM USER_INDEXES I JOIN USER_TABLES T ON I.TABLE_ID=T.TABLE_ID JOIN USER_SCHEMAS S ON T.SCHEMA_ID=S.SCHEMA_ID WHERE T.TABLE_NAME=UPPER('table_name');

Xugu、Oracle查看当前用户下的表索引信息:

  • Oracle:
    sql
    SQL> SELECT TABLE_OWNER,TABLE_NAME,INDEX_NAME FROM USER_INDEXES;
  • Xugu:
    sql
    SQL> SELECT S.SCHEMA_NAME,T.TABLE_NAME,I.INDEX_NAME FROM USER_INDEXES I JOIN USER_TABLES T ON I.TABLE_ID=T.TABLE_ID JOIN USER_SCHEMAS S ON T.SCHEMA_ID=S.SCHEMA_ID;

Xugu、Oracle查看当前库下所有索引信息:

  • Oracle:

    sql
    SQL> SELECT TABLE_OWNER,TABLE_NAME,INDEX_NAME FROM DBA_INDEXES;
  • Xugu:
    sql
    SQL> SELECT S.SCHEMA_NAME,T.TABLE_NAME,I.INDEX_NAME FROM DBA_INDEXES I JOIN DBA_TABLES T ON I.TABLE_ID=T.TABLE_ID JOIN DBA_SCHEMAS S ON T.SCHEMA_ID=S.SCHEMA_ID;

Xugu、Oracle查看某个表的约束信息:

  • Oracle:
    sql
    SQL> SELECT OWNER,TABLE_NAME,CONSTRAINT_NAME,CONSTRAINT_TYPE FROM USER_CONSTRAINTS WHERE TABLE_NAME=UPPER('table_name');
  • Xugu:
    sql
    SQL> SELECT S.SCHEMA_NAME,T.TABLE_NAME,C.CONS_NAME,C.CONS_TYPE FROM USER_CONSTRAINTS C JOIN USER_TABLES T ON C.TABLE_ID=T.TABLE_ID JOIN USER_SCHEMAS S ON T.SCHEMA_ID=S.SCHEMA_ID WHERE T.TABLE_NAME=UPPER('table_name');

Xugu、Oracle查看当前用户下表约束信息:

  • Oracle:
    sql
    SQL> SELECT OWNER,TABLE_NAME,CONSTRAINT_NAME,CONSTRAINT_TYPE FROM USER_CONSTRAINTS;
  • Xugu:
    sql
    SQL> SELECT S.SCHEMA_NAME,T.TABLE_NAME,C.CONS_NAME,C.CONS_TYPE FROM USER_CONSTRAINTS C JOIN USER_TABLES T ON C.TABLE_ID=T.TABLE_ID JOIN USER_SCHEMAS S ON T.SCHEMA_ID=S.SCHEMA_ID;

Xugu、Oracle查看当前库下的所有约束信息:

  • Oracle:
    sql
    SQL> SELECT OWNER,TABLE_NAME,CONSTRAINT_NAME,CONSTRAINT_TYPE FROM DBA_CONSTRAINTS;
  • Xugu:
    sql
    SQL> SELECT S.SCHEMA_NAME,T.TABLE_NAME,C.CONS_NAME,C.CONS_TYPE FROM DBA_CONSTRAINTS C JOIN DBA_TABLES T ON C.TABLE_ID=T.TABLE_ID JOIN DBA_SCHEMAS S ON T.SCHEMA_ID=S.SCHEMA_ID;