Dearg
Dearg

Reputation: 57

Non-unique foreign key Oracle?

I have two tables, data/model is fake for simplicity purposes:

Table A:

Order ID       Delivered
1              Y
2              N
3              Y

And

Table B:

Order ID       Customer ID    
1              123
1              234
1              455
2              789

Order ID is a primary key on Table A, and I want to use it as a Foreign Key on Table B. Is this acceptable, given that Order ID on Table B is not unique?

Please ignore any normalisation/structural issues, my question is simply whether you can have a non-unique foreign key, I just thought the illustration would help..

Thanks, Dearg

Upvotes: 0

Views: 781

Answers (1)

user330315
user330315

Reputation:

Is this acceptable, given that Order ID on Table B is not unique?

Yes, absolutely. This is the standard way of modeling a 1:many relationship

You should nevertheless find a primary key for TableB. If a customer cannot be assigned to more than one order, then using (order_id, customer_id) as the PK would make sense.

Upvotes: 2

Related Questions