我正在进行数据库作业,我遇到了几个部分的问题。我的数据库架构是这样的:
CREATE TABLE `Movies` (
`title` varchar(255) NOT NULL,
`year` int(11) NOT NULL (CHECK year > 1928),
`length` int(11) DEFAULT NULL (CHECK Length > 30 and Length < 280),
`genre` varchar(255) DEFAULT NULL (CHECK genre = “Drama” or genre = “comedy” or genre = “sciFi” or genre =”romance” or genre = “vampire”,
`academy_award` varchar(255) DEFAULT NULL,
`studioName` varchar(255) DEFAULT NULL,
`directorName` varchar(255) DEFAULT NULL,
PRIMARY KEY (`title`,`year`),
KEY `studioName` (`studioName`),
KEY `directorName` (`directorName`),
CONSTRAINT `Movies_ibfk_2` FOREIGN KEY (`directorName`) REFERENCES `Director` (`name`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `Movies_ibfk_1` FOREIGN KEY (`studioName`) REFERENCES `Studio` (`name`) ON DELETE CASCADE ON UPDATE CASCADE
)
CREATE TABLE `StarsIn` (
`movieTitle` varchar(255) NOT NULL,
`movieYear` int(11) NOT NULL,
`starName` varchar(255) NOT NULL,
PRIMARY KEY (`movieTitle`,`movieYear`,`starName`),
KEY `starName` (`starName`),
CONSTRAINT `StarsIn_ibfk_2` FOREIGN KEY (`starName`) REFERENCES `MovieStar` (`name`),
CONSTRAINT `StarsIn_ibfk_1` FOREIGN KEY (`movieTitle`) REFERENCES `Movies` (`title`)
CONSTRAINT `StarsIn_ibfk_2` FOREIGN KEY (`movieYear`) REFERENCES `Movies` (`year),
)
CREATE TABLE `Director` (
`name` varchar(255) NOT NULL,
`birthday` date DEFAULT NULL,
`nationality` varchar(255) DEFAULT NULL,
PRIMARY KEY (`name`)
)
CREATE TABLE `MovieStar` (
`name` varchar(255) NOT NULL,
`birthdate` date DEFAULT NULL,
`address` varchar(255) DEFAULT NULL,
`gender` varchar(255) DEFAULT NULL,
PRIMARY KEY (`name`)
)
CREATE TABLE `Studio` (
`name` varchar(255) NOT NULL,
`address` varchar(255) DEFAULT NULL,
PRIMARY KEY (`name`),
UNIQUE KEY `address` (`address`)
)
我必须添加更多约束:
在浏览MySQL约束文档后,我不确定如何完成此操作。任何帮助将不胜感激。