×

Good News Everybody!

The new search engine is LIVE!

Please report any problems to david (at) midrange.com.




Granted I'm not sure what I'm doing but, Isn't this backwards? Table 'Customer' should be the parent and 'CustomerGroup' should be the child. I thought the FK should be on the child table of CustomerGroup.



-----Original Message-----
From: MIDRANGE-L [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Rob Berendt
Sent: Wednesday, December 14, 2016 10:48 AM
To: Midrange Systems Technical Discussion
Subject: Re: setting up a foreign key

Using this as a start:
CREATE OR REPLACE TABLE rob.CustomerGroup( CompanyId INTEGER NOT NULL, GroupId Integer not null, GroupDescription VARCHAR(100) ALLOCATE(20), primary key (CompanyId, GroupId));

CREATE OR REPLACE TABLE rob.Customer(
CompanyId INTEGER NOT NULL,
Account# Integer not null,
GroupId Integer not null,
primary key (CompanyId, Account#));

I tried to go into http://myibmi:2001 and use the GUI in there to select multiple keys. I cannot get some of the checking to work. It doesn't seem to respond to my clicking on it.
Since it's not my problem I won't open a pmr on it but I recommend you do so.

A work around is to use Run SQL scripts and try this:
alter table rob.Customer
add foreign key(CompanyId, GroupId)
references rob.CustomerGroup (CompanyId, GroupId) on delete no action on update no action ;

BCCing you an image which the list will strip off.



Rob Berendt
--
IBM Certified System Administrator - IBM i 6.1 Group Dekko Dept 1600 Mail to: 2505 Dekko Drive
Garrett, IN 46738
Ship to: Dock 108
6928N 400E
Kendallville, IN 46755
http://www.dekko.com





From: Tammy Scott <tscott@xxxxxxxxxxxxxx>
To: "midrange-l@xxxxxxxxxxxx" <midrange-l@xxxxxxxxxxxx>
Date: 12/14/2016 11:19 AM
Subject: setting up a foreign key
Sent by: "MIDRANGE-L" <midrange-l-bounces@xxxxxxxxxxxx>



I am attempting to setup a foreign key using System I Navigator. I've
never created a foreign key before.

Here is my question and I did my best to explain it. I am very new to
all of this.

Customer table with columns.
CompanyID
Account#
Customergroup
Primary/unique key on customer table is CompanyID, Account#

CustomerGroup table with columns.
CompanyIDgrp
GroupID
GroupDescription
Primary/unique key on CustomerGroup table is CompanyIDgrp, GroupID

I need to setup a foreign key.

Does the Customer table need to have an index that has Customergroup as
part of the key in order for me to setup a foreign key? I cannot figure
out how to choose from the Customer Table, Customergroup.
Thanks for any help.
Tammy


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2026 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.