Should each table have a primary key?

I read somewhere, saying that every table must have a primary key to execute 1NF.

I have a tbl_friendship table.

The table has 2 fields: "Owner and friend."

The owner and friend fields are foreign keys of the auto increment id field in tbl_user.

Should this tbl_friendship have a primary key? Should I create an auto increment id field in tbl_friendship and make it primary?

+5
source share
7 answers

! , (Owner, Friend). , " " , (, "", (OwnerId, FriendId)

, , , .

, . http://michaeljswart.com/2011/01/ridiculously-unnormalized-database-schemas-part-zero/

+5

, .

, .. aka auto increment pk field.

"Friend" FK .


, " ", , , , , . , , . , , , ux , .

, , .

+4

, , ? .

( , ). .

+3

. (, ), . ( "", "" ) , , . , , . , , .

, , (, MySQL) Oracle.

+2

1NF ( , 1NF), , , . .

http://en.wikipedia.org/wiki/First_normal_form

, , , , - GUID, - , , .

+1

In the long run, your table will be much easier to manage if it has a primary key. At least you need to uniquely identify each record in the table. A field that is used to uniquely identify each record can also be a primary key.

0
source

Yes, each table must have (at least one) key. Duplication of rows in any table is undesirable for many reasons, so set a limit on these two columns.

0
source

All Articles