mysql - How do I add a boolean that can only have one true for one column name of the same type? -
i have table called computer , column office_id, computer_name, server. each office id have 1 computer server. if have multiple computers in office. 1 computer in office server , server required. there can't office no server.
if try implement in computers
table, need use trigger in mysql. other databases support things filtered indexes , computed columns making unnecessary, not mysql.
instead, add column offices
table:
create table offices ( . . . , serverid int not null, foreign key (serverid) references computers(computerid) );
this guarantee each office has 1 server. might need trigger guarantee officeid
in computers
table matches officeid
in offices
table, though.
Comments
Post a Comment