Anonymous Asked in Cars &Transportation · 2 weeks ago

Can a table have a foreign key without a primary key?

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. So in your case if you make AnotherID unique, it will be allowed. 19 июл. 2016 г.


Does a table with a foreign key need a primary key?

A foreign key is a set of one or more columns in any table (not necessarily a candidate key, let alone the primary key, of that table) which may hold the value(s) found in the primary key column(s) of some other table. So we must have a primary key to match the foreign key.

Can you have a table with just a foreign key?

There is no problem having a table that consists of foreign keys only. In your particular example it would be OK to remove the OrderID. Relational theory states that each table should have a candidate key so, ideally, the business rule you mention would be in place to make the foreign key only table a "good" table.

Related Questions

Relevance
Write us your question, the answer will be received in 24 hours