mysql - One-to-One Relationship -
i'm having trouble relationships mysql. tell me if 1 one relationship (between account , guest).
create table if not exists account ( accountid int unsigned not null comment 'primary key', guestfk int unsigned not null comment 'account linked particular guest', password varchar(20) not null comment 'password of guest account', constraint account_pk primary key (accountid), constraint account_fk foreign key (accountid) references hotel.guest(guestid) ); create table if not exists guest ( guestid int unsigned not null auto_increment comment 'primary key', addressfk int unsigned not null comment 'foreign key of guest address', vehiclefk int unsigned comment 'foreign key of guest vehicle', firstname varchar(50) not null comment 'first name of guest', lastname varchar(50) not null comment 'last name of guest', phonenum int unsigned not null comment 'phone number of guest', email varchar(50) not null comment 'e-mail address of guest', constraint guest_pk primary key (guestid), constraint address_fk foreign key (addressfk) references hotel.address(addressid), constraint vehicle_fk foreign key (vehiclefk) references hotel.vehicle(vehicleid), constraint email_uq unique (email) comment 'no 2 guests should have same e-mail address', constraint guest_uq unique (firstname, lastname, phonenum) comment 'no 2 guests should have same name , phone number' );
no isnt. failed supply constraint in account table guest foreign key. stands can have multiple accounts same guest.
consider marking guestfk unique. dictate relational model needs revisited guestfk serve primary key, remove need accountid.
in guest table consider composite key on following fields:
firstname,lastname,email,phone number
also, ensure aren't storing passwords , storing salted hashes.
Comments
Post a Comment