user_constraints 对比 user_cons_columns
user_constraints vs user_cons_columns
我正在尝试使用字典 USER_CONTRAINTS
查看我拥有的所有表的约束。这给了我 67 条记录(我所有表的所有约束加起来)
Post 我想查看应用这些约束的列。因此,当我对字典 USER_CONS_COLUMNS
执行 select* 操作时,它 returns 我有 69 条记录。
我的问题是记录数怎么会不一样呢?最终,两个字典视图都只获取那些与我(作为用户)相关的记录。
当我对这两个表执行连接时,这会导致返回不正确的记录数。
此外,如果上述行为是预期的,那么我应该在加入时选择两者中的哪一个作为主table/view?
My question is how can the number of records be different ?
很容易。例如复合外键。
SQL> create table test_m
2 (id number,
3 id_area number,
4 constraint pk_m primary key (id, id_area)
5 );
Table created.
SQL> create table test_d
2 (id number,
3 idm number,
4 idm_area number,
5 constraint fk_dm foreign key (idm, idm_area)
6 references test_m (id, id_area)
7 );
Table created.
SQL> select table_name, constraint_name, constraint_type
2 from user_constraints where table_name in ('TEST_M', 'TEST_D')
3 order by table_name;
TABLE_NAME CONSTRAINT_NAME C
------------------------------ --------------- -
TEST_D FK_DM R
TEST_M PK_M P
SQL> select table_name, column_name, constraint_name
2 from user_cons_columns where table_name in ('TEST_M', 'TEST_D')
3 order by table_name;
TABLE_NAME COLUMN_NAME CONSTRAINT_NAME
------------------------------ --------------- ---------------
TEST_D IDM_AREA FK_DM
TEST_D IDM FK_DM
TEST_M ID_AREA PK_M
TEST_M ID PK_M
SQL>
This is leading to incorrect number of records being returned when I perform a join on both these tables.
我会说你做的不对。但是,由于很难调试您看不到的代码,所以我不能说更多。
我正在尝试使用字典 USER_CONTRAINTS
查看我拥有的所有表的约束。这给了我 67 条记录(我所有表的所有约束加起来)
Post 我想查看应用这些约束的列。因此,当我对字典 USER_CONS_COLUMNS
执行 select* 操作时,它 returns 我有 69 条记录。
我的问题是记录数怎么会不一样呢?最终,两个字典视图都只获取那些与我(作为用户)相关的记录。
当我对这两个表执行连接时,这会导致返回不正确的记录数。
此外,如果上述行为是预期的,那么我应该在加入时选择两者中的哪一个作为主table/view?
My question is how can the number of records be different ?
很容易。例如复合外键。
SQL> create table test_m
2 (id number,
3 id_area number,
4 constraint pk_m primary key (id, id_area)
5 );
Table created.
SQL> create table test_d
2 (id number,
3 idm number,
4 idm_area number,
5 constraint fk_dm foreign key (idm, idm_area)
6 references test_m (id, id_area)
7 );
Table created.
SQL> select table_name, constraint_name, constraint_type
2 from user_constraints where table_name in ('TEST_M', 'TEST_D')
3 order by table_name;
TABLE_NAME CONSTRAINT_NAME C
------------------------------ --------------- -
TEST_D FK_DM R
TEST_M PK_M P
SQL> select table_name, column_name, constraint_name
2 from user_cons_columns where table_name in ('TEST_M', 'TEST_D')
3 order by table_name;
TABLE_NAME COLUMN_NAME CONSTRAINT_NAME
------------------------------ --------------- ---------------
TEST_D IDM_AREA FK_DM
TEST_D IDM FK_DM
TEST_M ID_AREA PK_M
TEST_M ID PK_M
SQL>
This is leading to incorrect number of records being returned when I perform a join on both these tables.
我会说你做的不对。但是,由于很难调试您看不到的代码,所以我不能说更多。