Почему это не работает ?? Мне нужен второй auto_increment, так как я использую его в качестве первичного ключа в другой таблице. Я хочу, чтобы правонарушения были непосредственно связаны с сообщениями, которые они нашли в
Create table ReportsFiled (
ReportID INT(10) NOT NULL AUTO_INCREMENT,
DateandTime DATETIME NOT NULL,
VehicleID VARCHAR(10) NOT NULL,
LicenseNumber VARCHAR(16) NOT NULL,
OffenceCommitted VARCHAR(255) NOT NULL,
ReportStatement VARCHAR(255) NOT NULL,
constraint pkReportsFiled primary key (ReportID, VehicleID),
constraint fkReportsFiledVehID foreign key (VehicleID) references Vehicles(VehicleID),
constraint fkReportsFiledLicNum foreign key (LicenseNumber) references People(LicenseNumber)
) ENGINE=InnoDB ;
Insert into ReportsFiled
(ReportID, DateandTime, VehicleID, LicenseNumber, OffenceCommitted, ReportStatement)
Values
(NULL, '2019-01-20 10:30:00', 'FD13 5TY', 'WRIGY96543867FD4', 'Moderate Speeding', 'Speeding in a residential area, given points and fine appropriate to the nature of the offence'),
(NULL, '2019-03-12 16:30:00', 'FT17 8HU', 'BARTO87252867BO4', 'Dangerous driving and Moderate Speeding', 'Driving recklessly in a residential area and driving above the speed limit, 3 points and £350'),
(NULL, '2019-05-28 12:23:00', 'SJ12 J8S', 'SMITH54398866QW4', 'Dangerous driving', 'Taking a corner too fast with no indication, 3 points given but no fine issued'),
(NULL, '2019-01-01 11:21:00', 'FT17 8HU', 'BARTO87252867BO4', 'Moderate Speeding', 'Driving at 42mph in a 30mph zone, 3 points and a £200 fine'),
(NULL, '2019-03-30 14:26:00', 'QW15 X4U', 'SPENC32975368DW8', 'Driving dangerously under the influence of alcohol', 'Licence ban and £2,500 fine'),
(NULL, '2019-08-21 22:14:00', 'FT17 8HU', 'BARTO87252867BO4', 'Driving while using a mobile device', 'Driving using a mobile device, 6 points and £500 fine') ;
Create table Offences (
OffenceID INT(10) NOT NULL AUTO_INCREMENT,
OffenceStatement VARCHAR(255) NOT NULL,
MaximumFine VARCHAR(100),
ReportID INT(10) NOT NULL AUTO_INCREMENT,
constraint pkOffences primary key (OffenceID, ReportID),
constraint fkOffencesReID foreign key (ReportID) references ReportsFiled(ReportID)
) ENGINE=InnoDB ;
Insert into Offences
(OffenseID, OffenceStatement, MaximumFine, ReportID)
Values
(NULL, 'Moderate Speeding', '3-6 points and £0-£200 fine', NULL),
(NULL, 'Driving under the influence of alcohol', 'Licence ban and £2,500 fine', NULL),
(NULL, 'Extreme Speeding', 'Licence ban and £2,000 fine', NULL),
(NULL, 'Dangerous driving', '3 points and £0-£500', NULL),
(NULL, 'Driving while using a mobile device', '6 points and £500 fine', NULL) ;