Foreign Key columns
hi, Does SQL Developer can show you the columns of a table involved in a foreign constraint? I can see in the DB tree the tables, then the constraints and I can see the table referenced but not the columns.
Is there anyway to see them? (I'm used to work with TOAD but I'm evaluating the posibility to migrate to SQL Developer)
Thanks
It's not very intuitive, but the only place I have seen the foreign key constraint columns listed in the UI is in the Edit Table dialog (short of generating the DDL or writing your own query to run in the worksheet).
To log an enhancement request to get this added, use the link in the "Feature Requests" sticky thread.
To do it yourself (ie not wait for the development team), you could write an extension to add a custom Constraints tab to the Tables information that displays the columns for the currently selected constraint.
theFurryOne
Similar Messages
-
Can we associate index with foreign key?
hello
i have searched and could not find the answer to the above;
i have a foreign key constraint on the tables; i added an index on that column as well;
however when i query the all_constraints, under index_name for this foreign constraint there is nothing; only when i have PK/UK i case see indexes associated with them;
will then oracle still associate my index with the FK constrained column? or i need to excplicity associate it with the foreign key column? if so, how to do that?
thx
rgdsHi,
UserMB wrote:
i have a foreign key constraint on the tables; i added an index on that column as well;It helps if you give a specific example, such as:
"I have a foreign key constraint, where emp.deptno references dept.deptno. (Deptno is the primary key of dept.) I created an index called emp_deptno_idx on emp.deptno as well."
however when i query the all_constraints, under index_name for this foreign constraint there is nothing; only when i have PK/UK i case see indexes associated with them;Not all indexes are associated with a constraint. In the example above, you wouldn't expect to see anything about the index emp_demptno_idx in all_constraints or in all_cons_columns.
will then oracle still associate my index with the FK constrained column? or i need to excplicity associate it with the foreign key column? if so, how to do that?In the situation above, Oracle will still use the index when the optimizer thinks it will help. You don't have to do anything else. -
Ora-2270 Error while adding foreign key constraint on top a view
While adding a constraint, referencing a foreign key column from a view raises error. However, it works fine over a table.
Here's the sample script:
create table t_temp (
sample_id number,
text varchar2(40))
alter table t_temp add constraint temp_pk
primary key (sample_id);
create view tempvw as select sample_id,text from t_temp;
create table t_sample (
uniq_id number,
sample_id number,
sample_text varchar(40));
=========
ALTER TABLE t_sample ADD CONSTRAINT FK_sample_temp
FOREIGN KEY (sample_id) REFERENCES t_temp (sample_id);
This works fine.
=========
==============
The following raises ERROR....
ALTER TABLE t_sample ADD CONSTRAINT FK_sample_temp1
FOREIGN KEY (sample_id) REFERENCES tempvw (sample_id);
Error starting at line 1 in command:
ALTER TABLE t_sample ADD CONSTRAINT FK_sample_temp1
FOREIGN KEY (sample_id) REFERENCES tempvw (sample_id)
Error report:
SQL Error: ORA-02270: no matching unique or primary key for this column-list
02270. 00000 - "no matching unique or primary key for this column-list"
*Cause: A REFERENCES clause in a CREATE/ALTER TABLE statement
gives a column-list for which there is no matching unique or primary
key constraint in the referenced table.
*Action: Find the correct column names using the ALL_CONS_COLUMNS
catalog viewWhat exactly are you trying to accomplish by having a
referential integrity constraint on a view (which is
not allowed). PKs and FKs are allowed on views. DISABLE NOVALIDATE is the only allowed state for them. View constraints are used for query rewriting: http://download.oracle.com/docs/cd/B19306_01/server.102/b14223/qradv.htm#sthref1457
Regards,
Dima -
SQL data modeller -- how to create 1 to 1 relationship foreign key ?
hi guys...
i got 2 tables..
table 1 - CFR
CFR_ID = primary key
table 2 - USER_PLAN
USER_ID = primary key
PLAN_ID,
CFR_ID = foreign key reference (table 1)
The business flows go like this..
insdie CFR table, it contain all records / transactions of a particular user/plan. everytime a new transaction occurs for a plan/user, a new CFR_ID / row will be generated.
after which, the newly generated CFR_ID for the new row , will be updated to the CFR_ID in USER_PLAN
Thus, there is always a 1 to 1 relationship between the 2 table regardless how many CFR_ID is generated for a particular USER_PLAN. as the CFR_ID in the USEr_plan table will always be the latest one generated inside the CFR table.
However, in the data modeller, i am unable to create such foreign key relationship... ANY idea how do i create a 1 on 1 foreign key relationship ? or there is no such way..
Thanks and Best Regards,
NoobHi philips,
Thanks for the wonderful reply..
Just to double comfirm with you,
even if i had set a unique constraint on CFR_ID(foreign key column), inside the relationship model, the relationship between the foreign key is still showing as a 1:m relationship right ?
just that a character 'U' will appear beside the CFR_ID column.
However the diagraphm is still showing a 1:M relationship.
is this correct ?
Regards,
Noob -
Hi,
Should I define foreign keys in logical fact table? I need to use "aggregation rule=count distinct" of the foreign key column in my reports.
Thanks.
AndyHi Andy,
You can add the foreign keys to your fact table as a measure column (count distinct aggregation).
Do not use these foreign keys to create foreign key joins in the logical layer. Always use complex joins (http://obibb.wordpress.com/2010/08/06/joins-in-oracle-bi-ee/)
Good Luck,
Daan Bakboord
http://obibb.wordpress.com -
Dimension foreign key on Fact gets updated with same value
Hi All,
I'm hoping someone has at least seen this problem and can provide insight.
Background:
- We are on OWB 10.2
- Fact table is Billing_F
- Fact table has foreign keys to Customer_Dim, SalesOrg_Dim, Time_Dim, etc.
- Fact table has update mode Update/Insert
Once in a while, every row in the Billing Fact gets updated with the SAME SalesOrg_Dim foreign key column value. In other words, the data would look like:
Before:
Line ID Amt SalesOrg_Key
1 100 19241
2 200 21925
3 140 08585
After:
Line ID Amt SalesOrg_Key
1 100 12345
2 200 12345
3 140 12345
*** The Source tables contain values in the Before table. ***
We can't reproduce this on a consistent basis. The only way to "correct" the data is to rerun the mapping from source -> staging -> fact again. No other change.
Please, has anyone else at least experienced this problem? If so, how were you able to fix it permanently?
Any help is greatly appreciated!
ireneHi Irene
Difficult to help here without reviewing your mappings/schedule but does SalesOrgKey 12345 represent a particular value e.g. Unknown, Default?
I suspect it's something to do with your load order in that the data in the dimension is not available/ready when the fact is loaded and therefore a default value is being inserted. When the fact load is rerun I'm guessing the load of the dimension has finished and therefore the key lookup returns the proper keys from the dimension. Is the dimension truncated and reloaded?
Regards
Si -
In JDO, can a foreign key be part of a primary key?
Hi, it's possible to have a foreing key a part of a primary key in JDO?
The JDO checker is complaining about that. It says "Primary key field 'person' cannot declare relationship".
For example, if I have an entity 'Person' (id, name) and and entity 'Pet' (name, age). Can I have the primary key of 'Person' (id) as a foreign key in 'Pet', and can I have a compound primary key in 'Pet' with 'name' and 'id' as the compound key?
Thanks in advance.
RafaelHi Dino,
First of all, thank you very much for your answer.
I read the article, but the solution proposed isnt clear to me. The theorical solution is: You'll have to map the foreign key columns to individual simple fields in your class rather than a single related object. At runtime, you can use the values of these fields to construct an application identity instance, which you can then use to fetch the related object
I dont understand the second sentence how would I fecht the related object at runtime?
Did you try it? Could you please send me an example? I change the type of my attributes to primitive types, and I left my .jdo and .map files as if those attributes were only primary keys how would I specify the relation at runtime with the other table?
My email is [email protected], I would really appreciate your help.
Best regards,
Isidro -
제품 : SQL*PLUS
작성날짜 : 1996-10-21
TIPS(9) : PARENT-CHILD관계를 갖는 TABLE의
PRIMARY key, FOREIGN key의 COLUMN 명과 POSITION 확인
==============================================================
** Name : Show_Position.Sql
** Usage : @Show_Positions Parent_Table Child_Table
** Description : Shows Primary And Foreign Key Positions
** WARNING : 이 문장은 해당 Table의 Constraint생성시 Naming
** Convention을 따른 경우에 적용되도록 되어 있다.
SET VERIFY OFF
CLEAR BREAK
BREAK ON CONSTRAINT_NAME ON TABLES
SELECT SUBSTR(CONSTRAINT_NAME,1,27) CONSTRAINT_NAME,
SUBSTR(TABLE_NAME,1,15) TABLES,
SUBSTR(COLUMN_NAME,1,15) COL_NAME,
SUBSTR(POSITION,1,3) POSITION,
SUBSTR(OWNER,1,7) OWNER
FROM USER_CONS_COLUMNS
WHERE TABLE_NAME = UPPER('&1')
AND CONSTRAINT_NAME LIKE 'PK%'
UNION
SELECT SUBSTR(CONSTRAINT_NAME,1,27) CONSTRAINT_NAME,
SUBSTR(TABLE_NAME,1,15) TABLES,
SUBSTR(COLUMN_NAME,1,25) COL_NAME,
SUBSTR(POSITION,1,3) POSITION,
SUBSTR(OWNER,1,7) OWNER
FROM USER_CONS_COLUMNS
WHERE TABLE_NAME = UPPER('&2')
AND CONSTRAINT_NAME LIKE 'FK%'
ORDER BY 1 DESC , 4 ASC;
< 실행 예 >
SQL> @SHOW_POSITIONS EMP_SERVICE EMP_SERVICE_LOG
CONSTRAINT_NAME TABLES COL_NAME POS
PK_EMP_SERVICE EMP_SERVICE EMP_ID 1
CUST_ID 2
FK_EMP_SERVICE_LOG_EC EMP_SERVICE_LOG EMP_ID 1
CUST_ID 2제품 : SQL*PLUS
작성날짜 : 1996-10-21
TIPS(9) : PARENT-CHILD관계를 갖는 TABLE의
PRIMARY key, FOREIGN key의 COLUMN 명과 POSITION 확인
==============================================================
** Name : Show_Position.Sql
** Usage : @Show_Positions Parent_Table Child_Table
** Description : Shows Primary And Foreign Key Positions
** WARNING : 이 문장은 해당 Table의 Constraint생성시 Naming
** Convention을 따른 경우에 적용되도록 되어 있다.
SET VERIFY OFF
CLEAR BREAK
BREAK ON CONSTRAINT_NAME ON TABLES
SELECT SUBSTR(CONSTRAINT_NAME,1,27) CONSTRAINT_NAME,
SUBSTR(TABLE_NAME,1,15) TABLES,
SUBSTR(COLUMN_NAME,1,15) COL_NAME,
SUBSTR(POSITION,1,3) POSITION,
SUBSTR(OWNER,1,7) OWNER
FROM USER_CONS_COLUMNS
WHERE TABLE_NAME = UPPER('&1')
AND CONSTRAINT_NAME LIKE 'PK%'
UNION
SELECT SUBSTR(CONSTRAINT_NAME,1,27) CONSTRAINT_NAME,
SUBSTR(TABLE_NAME,1,15) TABLES,
SUBSTR(COLUMN_NAME,1,25) COL_NAME,
SUBSTR(POSITION,1,3) POSITION,
SUBSTR(OWNER,1,7) OWNER
FROM USER_CONS_COLUMNS
WHERE TABLE_NAME = UPPER('&2')
AND CONSTRAINT_NAME LIKE 'FK%'
ORDER BY 1 DESC , 4 ASC;
< 실행 예 >
SQL> @SHOW_POSITIONS EMP_SERVICE EMP_SERVICE_LOG
CONSTRAINT_NAME TABLES COL_NAME POS
PK_EMP_SERVICE EMP_SERVICE EMP_ID 1
CUST_ID 2
FK_EMP_SERVICE_LOG_EC EMP_SERVICE_LOG EMP_ID 1
CUST_ID 2 -
Multiple foreign key joins between two tables
Hi,
I have a question about building a repository.
I have a date dimension and one fact. The fact table has about 10 foreign key columns that link to the date Dimension.
In this case should I create 10 aliases to create joins in the Physical and BMM layer or is there any other way to handle this situation.
I am asking this question because 10 aliases can get very confusing for me at the later point of time while creating reports.
Using OBIEE 10.1.3Hi
I have a follow up question on this.
I am okay with not seeing the different date tables under the Subject area. Even if it just shows a it as a Simple DATE Dimension I am good with it.
In this case which is the efficient way, creating 10 aliases or creating 10 joins in the physical layer. I just figured out that we can create multiple joins between the same set of two tables but do not know how will that effect the way BI server works.
Please help me in understanding this concept.
thanks
This request id for OBIEE 10.1.3 -
1:M Relationship - No Foreign Key is set
Hello,
I got a problem with 1:M relationships. The data I send is inserted without problems but the foreign key column is never set (null). Its very strange cause the reading works fine.
The Structur: got 2 tables ... Parent_tab and Child_tab.
I got 3 classes ... Parent_class (this one holds an ArrayOfChild_class), Child_class and ArrayOfChild_class (That holds a Collection of Child_classes). (I know its weird but i dont made this stuff, just have to work with it (and live with it)).
So i mapped the Parent_class to Parent_tab and Child_class to Class_tab (nothing unusale there) and made the ArrayOf Class to an aggregate and put it in the parent_class (where it belongs). In the ArrayOf Aggregate I mapped the Child_class 1:M. There I also set the Foreign Key (in this case 1:1 Child to Parent).
So, anyone still there or all lost :-)
Like I said... the reading works fine, but if i try to insert data it didnt set the foreign key. Tried alot but nothin worked.
Hope someone has an idea ...
btw. I am working with Toplink 9.0.3 Build 425.Hello,
I got a problem with 1:M relationships. The data I
send is inserted without problems but the foreign key
column is never set (null). Its very strange cause
the reading works fine.
The Structur: got 2 tables ... Parent_tab and
Child_tab.
I got 3 classes ... Parent_class (this one holds an
ArrayOfChild_class), Child_class and
ArrayOfChild_class (That holds a Collection of
Child_classes). (I know its weird but i dont made
this stuff, just have to work with it (and live with
it)).
So i mapped the Parent_class to Parent_tab and
Child_class to Class_tab (nothing unusale there) and
made the ArrayOf Class to an aggregate and put it in
the parent_class (where it belongs). In the ArrayOf
Aggregate I mapped the Child_class 1:M. There I also
set the Foreign Key (in this case 1:1 Child to
Parent).
So, anyone still there or all lost :-)
Like I said... the reading works fine, but if i try
to insert data it didnt set the foreign key. Tried
alot but nothin worked.
Hope someone has an idea ...
btw. I am working with Toplink 9.0.3 Build 425.I think this post is relevant to your situation. Please confirm if you are getting the same error.
Master-Detail Insertion problem -
How to update primary key column
Hi,
Can you suggest me best workaround/algorithm for below task:
(Oracle 10g, Solaris OS.)
Situation:
Table P has primary key column "Code", child tables F1, F2, ..., F15 reference with foreign key column "P_Code" column "P.Code", and we don't know which of the child tables has data for particular "P.Code" value.
Task:
Change "P.Code" value from 100 to 200. So that result would be that record P[Code = 100] should be updated as:
update P set
Code = 200
where Code = 100;And child tables column "P_Code" should be updated as:
update F1, F2, .., F15 set
P_code = 200
where P_code = 100;The best solution would be that one very easily can repeat that task.
Edited by: CharlesRoos on 28.12.2010 12:10If you are looking for reusable and repetitive solution, then may be...
SQL> CREATE TABLE p (p_code NUMBER PRIMARY KEY);
Table created.
SQL> INSERT INTO p VALUES(100);
1 row created.
SQL> INSERT INTO p VALUES(300);
1 row created.
SQL> INSERT INTO p VALUES(500);
1 row created.
SQL> commit;
Commit complete.
SQL> CREATE TABLE F1 (p_code NUMBER REFERENCES p(p_code));
Table created.
SQL> CREATE TABLE F2 (p_code NUMBER REFERENCES p(p_code));
Table created.
SQL> CREATE TABLE F3 (p_code NUMBER REFERENCES p(p_code));
Table created.
SQL> INSERT INTO F1 VALUES(100);
1 row created.
SQL> INSERT INTO F3 VALUES(100);
1 row created.
SQL> INSERT INTO F2 VALUES(500);
1 row created.
SQL> commit;
Commit complete.
SQL> CREATE OR REPLACE PROCEDURE update_child_parent(pi_p_code_old NUMBER,
2 pi_p_code_new NUMBER) IS
3 CURSOR table_to_update IS
4 SELECT table_name,
5 to_number(extractvalue(xmltype(DBMS_XMLGEN.getxml('SELECT count(*) c FROM ' ||
6 table_name ||
7 ' WHERE p_code=' ||
8 pi_p_code_old)),
9 '/ROWSET/ROW/C')) cnt
10 FROM user_tables
11 WHERE table_name IN ('F1', 'F2', 'F3');
12
13 BEGIN
14 EXECUTE IMMEDIATE 'ALTER TABLE p DISABLE PRIMARY KEY CASCADE';
15 UPDATE p SET p_code = pi_p_code_new WHERE p_code = pi_p_code_old;
16 FOR i IN table_to_update LOOP
17 IF i.cnt > 0 THEN
18 EXECUTE IMMEDIATE 'UPDATE ' || i.table_name || ' SET p_code=' ||
19 pi_p_code_new || ' WHERE p_code=' || pi_p_code_old;
20 END IF;
21 END LOOP;
22 EXECUTE IMMEDIATE 'ALTER TABLE p ENABLE VALIDATE PRIMARY KEY';
23 END update_child_parent;
24 /
Procedure created.
SQL> EXECUTE update_child_parent(100,200);
PL/SQL procedure successfully completed.
SQL> SELECT * FROM p;
P_CODE
200
300
500
SQL> SELECT * FROM F1;
P_CODE
200
SQL> SELECT * FROM F2;
P_CODE
500
SQL> SELECT * FROM F3;
P_CODE
200
SQL> INSERT INTO p VALUES(300);
INSERT INTO p VALUES(300)
ERROR at line 1:
ORA-00001: unique constraint (HR.SYS_C005931) violated
SQL> EXECUTE update_child_parent(500,900);
PL/SQL procedure successfully completed.
SQL> SELECT * FROM p;
P_CODE
200
300
900
SQL> SELECT * FROM F2;
P_CODE
900
SQL> -
Check constraint/foreign key combination
I would like to add a constraint (check, FK, or otherwise) that forces a value to be either -1 OR be in a foreign table. The statement below is invalid because you can't use subqueries, but I think it's clear what I'm trying to do. Can anyone
suggest a different approach?
Thanks!
ALTER TABLE cfg.ClientFieldThreshold ADD CONSTRAINT CK_cfg_ClientFieldThreshold_DBListID
CHECK (DBListID = -1 OR DBListID IN (SELECT ID FROM dbo.vwClientDatabases)
/* the subquery here isn't allowed */3 ways to do this.
1) use NULL instead of -1 as the value that does not have to be in the foreign table. Then you just need a normal foreign key (because a foreign key column that contains NULL is not checked against the foreign table. Sample code to do this
Create Table FooParent(ParentID int primary key);
Create Table FooChild(ChildId int primary key, ParentID int Null, Constraint FooChildFK Foreign Key(ParentID) References FooParent);
go
-- Can add row with NULL
Insert FooChild(ChildId, ParentID) Values (1, Null);
go
-- But cannot add row with any other value that is not in FooParent
Insert FooChild(ChildId, ParentID) Values (2, 25);
go
-- Check result
Select * From FooChild;
go
Drop Table FooChild;
go
Drop Table FooParent;
2) Add a dummy row to the parent table with a primary key of -1. Then, of course, all you need is a foreign key constraint.
3) Add a persisted computed column that is NULL whenever your column that you want to enforce the constraint against is equal to -1, otherwise just the value in that column. Then create a foreign key on the computed column. Sample code
Create Table FooParent(ParentID int primary key);
Create Table FooChild(ChildId int primary key, ParentID int Not Null, AlteredParentID As NULLIF(ParentID, -1) Persisted, Constraint FooChildFK Foreign Key(AlteredParentID) References FooParent);
go
-- Can add row with -1
Insert FooChild(ChildId, ParentID) Values (1, -1);
go
-- But cannot add row with any other value that is not in FooParent
Insert FooChild(ChildId, ParentID) Values (2, 25);
go
-- Check result
Select * From FooChild;
go
Drop Table FooChild;
go
Drop Table FooParent;
Tom -
Did elationship fields in entity bean with CMP same as foreign key in table
did elationship fields in entity bean with CMP same as foreign key in table database.so we don't have to make some foreign key column in table database.
did Container handle that both.
I need some answer
thank'sSuppose you have Group and user entity. Relation is 1-m. One group many users. When you create user, you dont need to send group id, All you need is create user and add it in collection (cmr-field) in group(user belongs to). Container will add its group id in user entity as well as in db.
-
Hello,
My interface has a Sql Server source datastore and an XML target datastore.
I woud like to create a sequence of values (0,1,2,3...) for the foreign key in the target. This foreign key is missing in the source datastore, hence, it cannot be mapped.
I'm unsure about the correct way of solving this issue.
Any help will be much appreciated...Ned Epstein wrote:
It makes sense for the trigger logic to assign the foreign key column trans_request_id in the table lsu_trans_resources_t with the value of the primary key from the parent table.Why?
Personally I disagree, and think this does not make sense. How can a trigger on the child table know under which parent key the child should be inserted? Magic?
Of course you can make some assumptions, such as: child rows are always inserted inside the same transaction that a parent row was inserted. In which case you could refer to parent_seq.currval.
But that, to me, sounds like an assumption you would not want to make. -
Traversing data along foreign keys?
Hi,
I am just wondering whether the following scenario is possible.
I have three tables A, B and C, The relationship between them is:
A ----> C ( many-to-one )
B ----> C ( many-to-one )
Now user updates the table C and I know I can capture what has changed by oracle triggers. Now I need to find the corresponding record in the parent table ( either A or B). Is it possible to somehow traverse the data along the foreign keys and when a record in table C is modified figure out whether the corresponding row and its columns/values belong in table A or table B.
Could this be done and where should I refer for more information about this use case.
ThanksYour scenario is not clear.
You say A--->C (many to one, which I would understand as many A to one C) but then say that either A or B is the parent in which case an ER model would show an arc:
C >--|------- A
C >--|------- B
ie C has foreign key columns A_ID and B_ID, and a check constraint to allow only A_ID or B_ID to be set, but not both.
Back to the trigger question; while updating C of course you can read data from A and B; is that what you are trying to do, or are you trying to insert a parent A or B if required?
Regards Nigel
null
Maybe you are looking for
-
N1 SPS 6.0 Installation problem on windows 2003
Hello, I have tried to install N1 SPS 6.0 on windows 2003. I was able to finish installlation successfully. But When I try to access tool from http://localhost:8080 , It is not working. I am new to tool , I am installing first time so not able to fig
-
Unable to load impl class error after WAR file rebuilt
Hi I have the source code for a working WAR file. I wanted to make a small change to the code and rebuilt the WAR. Now the previous WAR version works but even when I rebuild the WAR from the unedited code I get the error "unable to load impl class" a
-
i buy a mac mini from amazon, and it is registered on another Apple ID, and i need to change it to mine, how can i do that, note that i can't contact the previous owner of this mac, what shall i do to set it under my Apple ID. Thanks
-
Hi Friends, We have SAP_HR 600 SP18 level 58 and same EA_HR. We want to upgrade it to SAP_HR 602 and EA_HR602. We ahve tried it on service market place but not getting. Please send the link from where we can download the same. Regards Ganesh Datt Tiw
-
Default error comes when i Open Opportunity quick create
Dear all, When i open quick create of opportunity via account. We get an error message. Is there something i am missing in scoping? Error Message : Please enter a party with role Sales Unit. Regards, Dhruvin