我遇到了與MySQL的關係問題。有人能告訴我這是否是一對一的關係(在帳戶和客人之間)。一對一關係
CREATE TABlE IF NOT EXISTS account
(
accountID INT UNSIGNED NOT NULL COMMENT 'primary key',
guestFK INT UNSIGNED NOT NULL COMMENT 'account linked to 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 two guests should have the same e-mail address',
CONSTRAINT guest_UQ UNIQUE (firstName, lastName, phoneNum) COMMENT 'no two guests should have same name and phone number'
);
CAn 1個帳戶有1個以上的客人? – Mihai
編號我帳戶應該鏈接到一個客人,一個客人應該有一個帳戶。 –