0

Can someone please confirm if this is an appropriate use of a foreign key(this is just an example):

Application to book a meeting room;

tblBooking -> pkName,Time,fkRoomName;
tblRoom    -> pkRoomName, RoomNumber;

The UI will populate a dropdown menu using the pkRoomName data, when the booking is made the selected pkRoomName will then go to tblBooking fkRoomName.

Have I understood this correctly?

4

1 回答 1

0

Yes, if you want to ensure that any booking that specifies a room refers to a known room, then this is an appropriate use of a foreign key.

Note, however, that just declaring the foreign key relationship is not the same thing as requiring that all bookings specify a room. Records in tblBooking with a NULL value for fkRoomName will be permitted. If you want to require a room is specified, you must also use the NOT NULL constraint on the fkRoomName field.

Finally, a small matter of semantics. I would not use "fk" in the column name for the RoomName. This is because a foreign key is a different entity from the columns it includes. It is not uncommon to have foreign keys that include multiple columns and it is also not uncommon to have several different foreign key relationships out of a single table. Therefore fkRoomName is an appropriate name for the foreign key itself, but not so much for the column.

于 2013-07-03T17:11:56.280 回答