CREATE TABLE `ROUTE` (
`route_ID` INT NOT NULL,
`route_name` VARCHAR(45) NOT NULL,
`DELIVERY_VEHICLE_veh_ID` INT NOT NULL,
`DELIVERY_DRIVER_dr_ID` INT NOT NULL,
PRIMARY KEY (`route_ID`),
CONSTRAINT `fk_ROUTE_DELIVERY1`
FOREIGN KEY (`DELIVERY_VEHICLE_veh_ID` , `DELIVERY_DRIVER_dr_ID`)
(`VEHICLE_veh_ID` , `DRIVER_dr_ID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION);
我是SQL的新手,并试图通过练习来学习。我的语法中有一个我不理解的错误。任何帮助/建议?
(
VEHICLE_veh_ID
,DRIVER_dr_ID
)第9行
CREATE TABLE `DRIVER` (
`dr_ID` INT NOT NULL,
`dr_title` VARCHAR(15) NOT NULL,
`dr_fname` VARCHAR(45) NOT NULL,
`dr_lname` VARCHAR(45) NOT NULL,
`dr_DOB` DATETIME NOT NULL,
`dr_licenceNo` VARCHAR(45) NOT NULL,
`dr_phone` VARCHAR(15) NOT NULL,
`dr_email` VARCHAR(45) NOT NULL,
PRIMARY KEY (`dr_ID`));
CREATE TABLE `VEHICLE` (
`veh_ID` INT NOT NULL,
`veh_reg` VARCHAR(15) NOT NULL,
`veh_make` VARCHAR(45) NOT NULL,
`veh_model` VARCHAR(45) NOT NULL,
`veh_mileage` INT NOT NULL,
`veh_MOTdate` DATETIME NOT NULL,
`veh_servicedate` DATETIME NOT NULL,
PRIMARY KEY (`veh_ID`));
这些是与ROUTE相关的其他表格。我没有把DRIVER和VEHICLE表插入数据库的问题,ROUTE出了什么问题?
答案 0 :(得分:2)
看起来typeAheadId_1
表中有两个外键。
其中一个引用了ROUTE
表。
另一个引用DRIVER
表。
您的外键约束定义应该更像这样:
VEHICLE
答案 1 :(得分:0)
CREATE TABLE `ROUTE` (
`route_ID` INT NOT NULL,
`route_name` VARCHAR(45) NOT NULL,
`DELIVERY_VEHICLE_veh_ID` INT NOT NULL,
`DELIVERY_DRIVER_dr_ID` INT NOT NULL,
PRIMARY KEY (`route_ID`),
CONSTRAINT `fk_ROUTE_VEHICLE`
FOREIGN KEY (`DELIVERY_VEHICLE_veh_ID`)
REFERENCES `VEHICLE`(`veh_ID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_ROUTE_DRIVER`
FOREIGN KEY (`DELIVERY_DRIVER_dr_ID`)
REFERENCES `DRIVER`(`dr_ID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION);