sql >> Database >  >> RDS >> Mysql

Beste MySQL-tabelstructuur:2 ouders, 1 kind

CREATE TABLE Group ( 
    GroupID       integer    NOT NULL
  , Name          varchar(18)
  , Description   varchar(18)
  , GroupType     varchar(4) NOT NULL
  -- all columns common to any group type
);
ALTER TABLE Group ADD CONSTRAINT pk_Group PRIMARY KEY (GroupID) ;


CREATE TABLE BusinessGroup ( 
    GroupID   integer NOT NULL
  -- all columns specific to business groups
);
ALTER TABLE BusinessGroup
    ADD CONSTRAINT pk_BusinessGroup  PRIMARY KEY (GroupID)
  , ADD CONSTRAINT fk1_BusinessGroup FOREIGN KEY (GroupID) REFERENCES Group(GroupID) ;


CREATE TABLE SocialGroup ( 
    GroupID    integer NOT NULL
  -- all columns specific to social groups
);
ALTER TABLE SocialGroup
    ADD CONSTRAINT pk_SocialGroup  PRIMARY KEY (GroupID)
  , ADD CONSTRAINT fk1_SocialGroup FOREIGN KEY (GroupID) REFERENCES Group(GroupID) ;


CREATE TABLE Person ( 
    PersonID  integer NOT NULL
  , GroupID   integer NOT NULL
);
ALTER TABLE Person
    ADD CONSTRAINT pk_Person  PRIMARY KEY (PersonID)
  , ADD CONSTRAINT fk1_Person FOREIGN KEY (GroupID) REFERENCES Group(GroupID) ;


  1. Hibernate webapplicatie met MySQL-failover

  2. Meerdere hostnamen en meerdere privileges?

  3. Python 3.3 - Verbinding maken met Oracle-database

  4. Mysql-tabelreparatie is mislukt:kan geen nieuw tempbestand maken