Question re: setting Primary Key

S

Studebaker

I have 2 tables: Table A & Table B

Table A has field names: This is a table of owners of rental rooms.
owner ID, last name, first name, street, city, state, postal code, telephone

The owner ID I have picked in this table to be the primary key b/c it is
unique to each owner.

Table B has field names: This is a table of rental rooms
Room #, # of Bedrooms, # of Bathrooms, Sleeps How Many?, Linens, Weekly
Rate, Owner Last Name, and I added Owner ID.

I had trouble setting the primary key for this one. I chose the Room# as the
primary key b/c it is unique to each room. I added a field name called owner
ID here b/c I'm going to relate these 2 tables. Is that the idea behind
choosing a primary key for Table B? I didn't make Owner ID or any other field
in this table the primary key b/c you can have more than one owner ID rent
out a room.

Can someone verify I have the right idea?

Thank you.
 
J

John W. Vinson

I have 2 tables: Table A & Table B

Table A has field names: This is a table of owners of rental rooms.
owner ID, last name, first name, street, city, state, postal code, telephone

The owner ID I have picked in this table to be the primary key b/c it is
unique to each owner.

Table B has field names: This is a table of rental rooms
Room #, # of Bedrooms, # of Bathrooms, Sleeps How Many?, Linens, Weekly
Rate, Owner Last Name, and I added Owner ID.

I had trouble setting the primary key for this one. I chose the Room# as the
primary key b/c it is unique to each room. I added a field name called owner
ID here b/c I'm going to relate these 2 tables. Is that the idea behind
choosing a primary key for Table B? I didn't make Owner ID or any other field
in this table the primary key b/c you can have more than one owner ID rent
out a room.

Can someone verify I have the right idea?

Thank you.

If there will never be more than one room with the same Room # (by the way,
it's best to use a name such as RoomNo; the # character is a date delimiter
and it's best not to use it in fieldnames), then yes, you can use the RoomNo
(Room #) as the primary key. That's what a primary key is for - to uniquely
identify a record.

The OwnerID field (don't use blanks in fieldnames either, preferably) would be
used as a "Foreign Key" to the Rooms table. You can use the Relationships
window to define this relationship - add the Rooms table and the owners table,
and drag OwnerID from Owners to OwnerID in Rooms; check the Enforce
Referenetial Integrity button, and you will prevent errors such as assigning a
room to a nonexistant owner.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top