Two foreign keys to one primary key
I'm having trouble displaying information for two foreign keys in my table. My goal is to display the first and last name of both a Project Manager and Account Manager. I have a "Jobs" table linked to an "Employees" table.
Jobs
ProjectMgrID
AcctMgrID
Employees
EmployeeID
LastName
FirstName
Both ProjectMgrID(fk) and AcctMgrID(fk) are linked to EmployeeID(pk). When I build a query, I am not sure how to display both the FirstName and LastName fields for both. It only allows me to add them once, and when I add them twice it just displays the same information twice.
Please help!
Welcome to the forum!
It looks like you'll need to join to EMPLOYEES twice.
Something like the following:
SELECT e1.firstname
, e1.lastname
, e2.firstname
, e2.lastname
FROM jobs
JOIN employees e1 ON e1.employeeid = jobs.projectmgrid
JOIN employees e2 ON e2.employeeid = jobs.acctmgrid
;
Similar Messages
-
Can I have more than one primary key ???????
Hi
Assuming an application has designed as CMP with findByPrimaryKey( ) method having more than one parameter.
Example :- findByPrimarykey(String val1, String val2)
Is it possible to have two parameters fot the finder methods instead using PrimaryKey class ?
If yes, what are the changes required for following deployment descriptor element. ?
1. <prim-key-class></prim-key-class>
2. <primkey-field></primkey-field>
Regards
Edward.IIf a primary key has more than one primary key fields; is a composite primary key, a primary key class is required.
The parameter of the findByPrimaryKey() method is the primary key class.
findByPrimaryKey(PrimaryKeyClass pkClass)
Deepak -
Can we have more than one primary key constraint to a Oracle Table?
Hi,
Can we have more than one primary keys to a single table in oracle? ( Not the composite key)
Please somebody answer..
Regards,
Alaka811935 wrote:
Can we have more than one primary keys to a single table in oracle? ( Not the composite key)
In principle a table can have multiple keys if you need them. It is a very strong convention that just one of those keys is designated to be "primary" but that's just a convention and it doesn't stop you implementing other keys as well.
Oracle provides two uniqueness constraints for creating keys: the PRIMARY KEY constraint and the UNIQUE constraint. The PRIMARY KEY constraint can only be used once per table whereas the UNIQUE constraint can be used multiple times. Other than that the PRIMARY KEY and UNIQUE constraints serve the same function (always assuming the column(s) they are applied to are NOT NULL). -
Hi,
How to create more than one primary key in TT
CREATE TABLE LOOKUP (KEY NUMBER NOT NULL PRIMARY KEY, VALUE CHAR (64))
In Oracle we can create Composite Primary key
CREATE TABLE LOOKUP (KEY NUMBER NOT NULL , VALUE CHAR (64) , CONSTRAINT constraint_name PRIMARY KEY (KEY,VALUE) )
Thanks!Hi 933663,
What is a problem?
Command> CREATE TABLE recreation.members
(membername CHAR(20) NOT NULL,
club CHAR(15) NOT NULL,
memberphone SMALLINT,
PRIMARY KEY (membername, club));
Command> regards,
Gennady -
VLD-0201:Table has more than one primary key
hi
i'm working with OWB 9.2,I was imported the table from database,when i validating that it is giving message:
VLD-0201:Table has more than one primary key
vld-0209:Duplicate unique key i.e:cust_acc and SYS_C00435 detected.
Can i use this table and generate the mapping with out any errors?
Any help will be very generate.Hi Ashok,
I'm quite curious how you managed to get a table with 2 PK's.
I tried it myself:
=======================================================
SQL>create table x(c1 number constraint pk1 primary key,c2 number constraint pk2 primary key, c3 date);
create table x(c1 number constraint pk1 primary key,c2 number constraint pk2 primary key, c3 date)
ERROR at line 1:
ORA-02260: table can have only one primary key
SQL>ed
Wrote file afiedt.buf
1* create table x(c1 number constraint uk1 unique,c2 number constraint uk2 unique, c3 date)
SQL>/
Table created.
=====================================================
As you can see, trying to create a table with more than 1 PK is impossible. With Unique Key, that IS possible (see second example).
I don't expect mappings to function properly with such an error message.
Is it possible for you to drop the table in the database, correct the definition of the table in OWB and then deploy that corrected version to the database?
If on the other hand the table on the database is correct (i.e. has only one PK) then the import into OWB obviously did not go well and I'd suggest you drop the imported definition and try to import it again.
Cheers, Patrick -
FRM-30100: Block must have at least one primary key item.
Hi,
I am customizing a form in 6i. I added one database column to one block using data block wizard. Form Compiled successfully. But when I compile the form in Unix, it compiled the form and created the .fmx file but gave the below error.
FRM-30100: Block must have at least one primary key item. Can you please help me what needs to be done to fix this.
Thanks,
HCPlease see if these docs help.
Troubleshooting: FRM-30085 [ID 783768.1]
Basing a Block on a Stored Procedure - Sample Code [ID 66887.1]
Thanks,
Hussein -
CHILD form error FRM-30100: Block must have at least one primary key item.
Hi friends,
I have increased the DML array of the child block from 1 to 10, but it throws me error:
FRM-30100: Block must have at least one primary key item.
Block: CEC_ADJUSTMENT_RECON
Form: CEC_ADJ
FRM-30085: Unable to adjust form for output.
How does a form know that the table does not have primary key? Is it referring to it?
Thanks a lotI dont understand why do you increase the DML array size..
Because it says in the HELP
Specifies the maximum array size for inserting, updating, and deleting records in the database at one time.
A larger size reduces transaction processing time by reducing network traffic to the database, but requires more memory. The optimal size is the number of records a user modifies in one transaction.
The FRM-30100 comes not because of the above property..
If your query data source type is other than TABLE, it is a must to set at least one database field's PRIMARY KEY ITEM PROPERTY in the block to be a YES. -
Two foreign keys reference on primary key
There are two tables:
1) table CALENDAR with primary key: cal_id
2) table FACTS with some columns, two of them are dates: cal_id_start_process, cal_id_stop_process
we want on physical layer create two foreign keys for cal_id_start_process and cal_id_stop_process columns reference on CALENDAR.cal_id
When we create foreign key for cal_id_start_process: we choose this column and choose CALENDAR table and its primary key. But when we want to create foreign key for cal_id_stop_process - we cannot coose table CALENDAR again.
Is this rigth, that only one column from table can reference on specified primary key in CALENDAR table?
How to create two foreign key on one table primary key?More complex. In your example there'll be such SQL:
select c.cal_id, f.cal_id_start, f.cal_id_stop
from CALENDAR c, FACTS f
where c.cal_id = f.cal_id_start and c.cal_id = f.cal_id_stop
(It meens FACTS.cal_id_start = FACTS.cal_id_stop )
In my case, I want for such join:
select c1.cal_id, c2.cal_id, f.cal_id_start, f.cal_id_stop
from CALENDAR c1, CALENDAR c2, FACTS f
where c1.cal_id = f.cal_id_start and c2.cal_id = f.cal_id_stop
Edited by: annylut on Dec 22, 2011 3:33 PM -
More then one Primary Key?
During application building there is only a place to specify 2 primary keys. If I want to use more then 2 where would I do this at? Thanks Agains!!
Not possible if you are using the Automatic Row Fetch and Processing DML.
One workaround is to define a view, but that will have a drawback if you wish to use the returning clause (i.e. "Return Key Into Item" under Automatic Row Processing). This is because Oracle SQL does not support the returning clause with views.
You have to develop the PL/SQL code to accomodate the custom table configuration with more than two primary keys.
Regards,
John -
How to create one primary key for each vendor
Hi all
i am doing IDOC to jdbc scenario
i am triggering idoc from R/3 and the data is going into DB table vendor through XI.
structures are as follows:
sender side: ZVendorIdoc (this is a customized IDOC , if i triger IDOC for multiple vendors then it triggers only 1 idoc with multiple segment )
Receiver side:
DT_testVendor
Table
tblVendor
action UPDATE_INSERT
access 1:unbounded
cVendorName 1
cVendorCode 1
fromdate 1
todate 1
Key1
cVendorName 1
if i trigger idoc for multiple vendors ,for example vendor 2005,2006 and 2010 . then i can see that the only key comes from the very first field (2005) and the whole record for vendor 2005,2006 and 2010 goes into the table with this(2005) as a primary key
now again if i send data for these three vendor 2005, 2006 , 2010, in which record for the vendor 2005 is same and for 2006 and 2010 are different than it takes 2005 as a primary key and it does not update the data in the table.
my requirement is like this: for each vendor there should be one unique key assigned.
for above said example there should come three keys one for each vendor .
could you please help me how to do this???????????Hi,
In Mapping Make the statement is 0-unbounded.For each vendor create a statement.This will solve your problem.
Regards,
Prakasu.M -
제품 : 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 -
How shall we do validation for Unique Key and Multiple Primary Key?
Hi,
I have table created From EO in which one column is checked as Unique.
How to do validation for column checked as Unique.
I know how to do validation for column checked as primary key.
Below is sample code for primary key validation
if (getRvSize() != null)
throw new OAAttrValException(OAException.TYP_ENTITY_OBJECT,
getEntityDef().getFullName(), // EO name
getPrimaryKey(), // EO PK
"RvSize", // Attribute Name
value, // Attribute value
"AK", // Message product short name
"FWK_TBX_T_EMP_ID_NO_UPDATE"); // Message name
if (value != null)
OADBTransaction transaction = getOADBTransaction();
Object[] rvKey = {value};
EntityDefImpl rvDefinition = xxczVAGCSRVSizingEOImpl.getDefinitionObject();
xxczVAGCSRVSizingEOImpl rv =
(xxczVAGCSRVSizingEOImpl)rvDefinition.findByPrimaryKey(transaction, new Key(rvKey));
if (rv != null)
throw new OAAttrValException(OAException.TYP_ENTITY_OBJECT,
getEntityDef().getFullName(), // EO name
getPrimaryKey(), // EO PK
"RvSize", // Attribute Name
value, // Attribute value
"AK", // Message product short name
"FWK_TBX_T_EMP_ID_UNIQUE"); // Message name
What changes need to be done for above code in order to do the validation for Unique Key.
I have one more Question
How shall we do the Validation for Multiple Primary Key in a table?
- Mithun1. If you just validate on one attribute like your unique key, then put your logic in the set<Your AttributeName) method
2. If you want to do the cross validation ( like validating multiple attributes) then put your logic in the validateEntrity Method
How to do that?
1. Create a Validation View object.
2. Associate your VVO to the VAM
3. Create entity expert.
4. Have method in entity expert for your validation (you would be calling AM and then VO execute the query and do the validation.
5. You would be calling the Entity experty method from your EO either setMethods or validateEntity.
I have given just the high level points.
Hope this helps.
Thanks,
RK -
Can the Primary Key also be Primary key in another table
Hi all,
I am working on a project. The project specification says:
Project table contains details of projects and the project number *(proj_no)* is the key.
project ( proj_no , proj_date, proj_desc, proj_type, proj_status, s_no, cust_no)
purchase_order table contains details of the purchase orders for each project and the combination of project
number and a purchase order number *(proj_no, po_no) form the key.*
purchase_order ( proj_no , po_no, po_date)
How can I have proj_no in the project table and in the purchase_order as primary keys?
If I create a composite key in the purchase_order table making the ( proj_no, po_no) as primary key. How can I make the project_no in the project table a primary key too?
Is there a solution for it?
CREATE TABLE purchase_order(
po_no NUMBER(5) NOT NULL,
proj_no NUMBER(5) NOT NULL,
po_date date,
CONSTRAINT p_o_po_no_proj_no_pk PRIMARY KEY (po_no,proj_no));
Thanks!!!Hi,
I think I'd set the project no in the projects table a primary key, and project no in the purchase orders table a foreign key constraint to the projects table, combined with a unique, not null constraint in the table.
That, in addition to a unique, not null constraint on the purchase orders column, and a composite primary key should fulfill the requirements.
Best of luck!
Johan -
Partition key on non primary key column
I have scenario where the table has defined non primary key column as "partition key".
I was wondering how it will affect the purge/archive process if the index and table are using different column (they are not aligned)?
What should be the solution to this scenario?
Can I use the non primary key column as partition key? Is this affect purging/archiving or switching -IN or OUT partitions?
Here is the article which Im following but didn't get the precise answer:
"When the indexes and the table use the same partitioning function and columns in the same order, the table and index
are aligned."
https://msdn.microsoft.com/en-US/library/ms345146%28v=SQL.90%29.aspx?f=255&MSPPError=-2147217396#sql2k5parti_topic9
Look at "Index
Partitioning" and "Defining
the Partitioning Key" section.
ZKIf it non aligned, you cannot do switching in or out. to switch, you should have aligned partitons.
Hope it Helps!! -
How I can do this update, when I have two records (one primary key, no seq)
How I can do this update in pl\sql
Here is the table with some data
CREATE TABLE INSERT_TE
PIDM VARCHAR2(8),
FORM_ID VARCHAR2(2),
TEACHER VARCHAR2(30)
INSERT into INSERT_TE
PIDM,
FORM_ID,
TEACHER
SELECT
'1106651',
'TE',
'Teacher, Alber Howard'
from dualcommit;
INSERT into INSERT_TE
PIDM,
FORM_ID,
TEACHER
SELECT
'1106651',
'TE',
'Teacher, Alber2 '
from dualcommit;
INSERT into INSERT_TE
PIDM,
FORM_ID,
TEACHER
SELECT
'2321241',
'TE',
'Teacher, Silly Billy '
from dualcommit
You are going to ended with something like this: In a cursor..
PIDM FORM_ID TEACHER
1106651 TE Teacher, Alber Howard
1106651 TE Teacher, Alber2
2321241 TE Teacher, Silly Billythen I need to update a table
if the there is only one record like this one 2321241 TE Teacher, Silly Billy
not problem I do this
UPDATE saturn.sarchkl
SET
sarchkl_receive_date = SYSDATE,
sarchkl_activity_date = SYSDATE,
sarchkl_source = 'U',
sarchkl_source_date = SYSDATE
WHERE
sarchkl_pidm = v_pidm3
AND sarchkl_receive_date IS NULL
AND sarchkl_term_code_entry = p_term
AND sarchkl_admr_code = 'REC1'But if there is a PIDM (pk) with two records
PIDM FORM_ID TEACHER
1106651 TE Teacher, Alber Howard
1106651 TE Teacher, Alber2 I need to do 2 updates (notice the AND sarchkl_admr_code rec1 for the firs and rec2 for the second
The first record should update the table when the condition is sarchkl_admr_code = 'REC1' and the second record with the
condition is sarchkl_admr_code = 'REC2'
UPDATE saturn.sarchkl
SET
sarchkl_receive_date = SYSDATE,
sarchkl_activity_date = SYSDATE,
sarchkl_source = 'U',
sarchkl_source_date = SYSDATE
WHERE
sarchkl_pidm = v_pidm3
AND sarchkl_receive_date IS NULL
AND sarchkl_term_code_entry = p_term
AND sarchkl_admr_code = 'REC1'and
UPDATE saturn.sarchkl
SET
sarchkl_receive_date = SYSDATE,
sarchkl_activity_date = SYSDATE,
sarchkl_source = 'U',
sarchkl_source_date = SYSDATE
WHERE
sarchkl_pidm = v_pidm3
AND sarchkl_receive_date IS NULL
AND sarchkl_term_code_entry = p_term
AND sarchkl_admr_code = 'REC2'I am doing this in pl\sql, I don't have a sequence in the table INSERT_TE, how I know that the first record in
1106651 TE Teacher, Alber Howard
1106651 TE Teacher, Alber2 update a rec1 and the second updates when sarchkl_admr_code = 'REC2',
I guess I can create a sequence, but I am inserting a table from a select satement, I am getting the error
ORA-02287: sequence number not allowed here, when I try to do the following:
INSERT INTO SYTEACH
SYTEACH_PIDM,
SYTEACH_ID,
SYTEACH_TEACHER,
SYTEACH_SEQ
SELECT
DISTINCT
spriden_pidm,
sarchkl_admr_code,
szsform_form_id,
szsform_schl_off_type||', '||szsform_schl_off_firstname||' '||szsform_schl_off_lasttname teacher,
SZSFORM_SEQ.NEXTVAL
FROM saturn_midd.szsform, saturn.spriden, saturn.sarchkl
WHERE spriden_ntyp_code = 'CAPP'
AND szsform_common_app_id = spriden_id
AND spriden_pidm = sarchkl_pidm
AND sarchkl_admr_code = 'REC1'
AND szsform_form_id = 'TE'
What is the simple way of doing this update..Hi,
you said:
>
But if there is a PIDM (pk) with two records
PIDM FORM_ID TEACHER
1106651 TE Teacher, Alber Howard
1106651 TE Teacher, Alber2
>
No! pks are unique! (otherwise we don't call them pk)
For your table you could define a unique like this:
PIDM column + a sequence. (new column):
ALTER TABLE INSERT_TE ADD(TEACH_SEQ NUMBER)
UPDATE INSERT_TE x
SET TEACH_SEQ =
(SELECT n
FROM (SELECT ROWID rid,
ROW_NUMBER() OVER(PARTITION BY pidm ORDER BY TEACHER) n
FROM INSERT_TE t) s
WHERE s.rid = x.ROWID)
PIDM FORM_ID TEACHER TEACH_SEQ
1106651 TE Teacher, Alber Howard 1
1106651 TE Teacher, Alber2 2
2321241 TE Teacher, Silly Billy 1I need to do 2 updates (notice the AND sarchkl_admr_code rec1 for the firs and rec2 for the second
The first record should update the table when the condition is sarchkl_admr_code = 'REC1' and the second record with the condition is sarchkl_admr_code = 'REC2'
>
normally no.
but you can (now) do
select PIDM, FORM_ID, TEACHER, 'REC'||TEACH_SEQ TEACH_SEQ from INSERT_TE
PIDM FORM_ID TEACHER TEACH_SEQ
1106651 TE Teacher, Alber Howard REC1
1106651 TE Teacher, Alber2 REC2
2321241 TE Teacher, Silly Billy REC1and use the last column for you update ...
Edited by: user11268895 on Aug 20, 2010 2:01 PM
Maybe you are looking for
-
Problem: Uploading Video To iPod
Ok here's the issue. 8 times out of 10 when I connect my iPod via USB, it does not give me the option to upload video to my iPod. I would click on the "iPod Options" where you can select Automatically update this and that... and I only see four stand
-
AnyConnect Secure Mobility Client Connection Issue
Hello all, I am specifically having issue of unable to connect do VPN using AnyConnect Secure Mobility Client. This issue is only happening on my Windows7 machine. All of this use to work before properly without any issue. All of sudden now I am gett
-
Hallo habe das problem das Pr CC meine AVI nicht nimmt der WMP und der VLC player liest es. Habe eine AVI Code Pack installiert aber geht immer noch nicht. Was kann ich tun? LG Micha
-
Help with Resolution on External Monitor
I want to set my HP Envy 15t to drive an external monitor, not as an extension, but rather as my primary monitor. My external monitor is a Viewsonic VX2250, a little older, and requires that I use a HDMI-to-VGA adapter. (The Viewsonic also has DVI
-
Can multi-colored round ball be stopped?
The round multicolored ball comes up and continues sometimes for several minutes......is this pesky little thing stoppable? Is it only with Mac's? I am hoping someone out there has a method of destruction for that little ball..........thanks!