Ilovetofake
Ilovetofake

Reputation: 59

Creating many-to-many relation with a junction table

I need to construnct a junction table for many-to-many relations between two parent tables. The design is set. How is it possible to constraint my junction table as a child table when FK's will become duplicates by default?

enter image description here

create table FactInternetSalesReason
( SalesOrderNumber int,
  SalesOrderLineNumber int,
  SalesReasonKey int,
  CONSTRAINT FK_SalesOrder FOREIGN KEY (SalesOrderNumber, SalesOrderLineNumber) REFERENCES FactInternetSales (SalesOrderNumber, SalesOrderLineNumber),
  CONSTRAINT FK_SalesReason FOREIGN KEY (SalesReasonKey) REFERENCES DimSalesReason (SalesReasonKey)
);

Upvotes: 1

Views: 378

Answers (1)

Tab Alleman
Tab Alleman

Reputation: 31785

A Foreign Key can contain duplicates (try it). A Primary Key cannot.

Upvotes: 1

Related Questions