0

Is it possible to create a foreign key - FK in one table which will refer to a normal atribute (not Primary Key - PK) in another table?

MarcM
  • 2,173
  • 22
  • 32
Rafael Valente
  • 763
  • 1
  • 6
  • 13

2 Answers2

0

If your are working in a RDBMS:

Yes, you can. But ONLY if values of the FK destination field are unique.

The column pointed from the FK MUST have unique values to keep database referential integrity safe.

A way to assure so is defining a Unique Constraint on it.

Edited to clarify:

Table A has a FK column pointing to table B, column named B_anycolumn.

There's no actual need to B_anycolumn from being PK from table B, but it must have a Unique Constraint to ensure that all values in it are different.

Even though this is possible, normal relationships between tables are to PK columns, since are always unique by definition.

MarcM
  • 2,173
  • 22
  • 32
0

Yes. A FOREIGN KEY constraint does not have to be linked only to a PRIMARY KEY constraint in another table; it can also be defined to reference the columns of a UNIQUE constraint in another table.

refer this:

Foreign Key to non-primary key

Community
  • 1
  • 1
Sunil tc
  • 2,482
  • 4
  • 19
  • 46