Question

I'd like to define a PK for the Administers entity type which is an intersection entity type for n:m relationship between Person and Server.

Can someone explain what are the rules if one side of the relationship is optional?

Person (PersonID PK)
Server (ServerID PK)

Was it helpful?

Solution

Can someone explain what are the rules if one side of the relationship is optional?

The rule is "Don't do that." The reason is that the predicate for that table doesn't make sense if you leave out either of the two columns.

If a person

  • can be assigned a server to administrator, but
  • isn't currently administering any servers, and
  • you need to store the fact that a particular person might administer a server, then

your model is wrong. You should probably add another table for server administrators.

create table person (
  person_id integer primary key,
  ...
);

create table server (
  server_id integer primary key, 
  ...
);

-- Persons who are allowed to administer a server
create table server_admins (
  person_id integer primary key
    references person (person_id), 
  ...
);

create table administers (
  person_id integer not null 
    references server_admins (person_id),
  server_id integer not null
    references server (server_id),
  primary key (person_id, server_id), 
  ...
);

If you need to, you can create views to show a) which servers currently have no administrator, and b) which server administrators currently administer no servers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top