user6826584
user6826584

Reputation: 81

Entity-relationship model

I am creating a simple entity-relationship model. Here I have one or more animals that can get one or more services. ER-model My question is which attributes's the connection type "get" going to have. I was thinking that it will get the unique attributes of animals and svervice that is "animal-ID" and "service-ID", and that will be foreign keys in "get".

Upvotes: 1

Views: 189

Answers (2)

Nmk
Nmk

Reputation: 1321

This will be used to link the tables that were originally related in an M:N relationship

Upvotes: 0

NLink
NLink

Reputation: 485

Typical many-to-many relationship looks like table with two columns referencing two entities. In your case it's (actual syntax depends on dbms):

CREATE TABLE Get (
  animal_id INT NOT NULL,
  service_id INT NOT NULL,
  FOREIGN KEY animal_id REFERENCES animal (animal_id),
  FOREIGN KEY service_id REFERENCES service (service_id)
)

Sometimes it makes sense to extend linking table by some link properties. Like:

CREATE TABLE Get (
  animal_id INT NOT NULL,
  service_id INT NOT NULL,
  service_paid BOOLEAN,
  provided_date DATE,
  FOREIGN KEY animal_id REFERENCES animal (animal_id),
  FOREIGN KEY service_id REFERENCES service (service_id)
)

But in general it's just two foreign keys.

Upvotes: 1

Related Questions