触发以允许每人1辆车

时间:2019-03-13 16:26:49

标签: mysql

大家好,所以我正在尝试创建一个触发器。商业规则是一个人只能租一辆车。即他/她不能在同一天预订BMW和Audi。我试图把东西粘在一起..?我无法完全确定如果有人预订了此特殊汽车,该如何在IF语句中表达它。我想到了使用vehicle_collections,并把预订日期>收集日期...我是初学者。我拿出了一些数据,因为这篇文章有字数限制。

DELIMITER //
CREATE TRIGGER Carperperson
BEFORE INSERT ON bookings
FOR EACH ROW 
BEGIN
IF NEW.vehicle_id = ?THEN
SIGNAL SQLSTATE '45000' set message_text='You can only book one car per single customer a day!';


DELIMITER //

我还提供了表格结构

Drop database if exists g00337857abu;
create database g00337857abu CHARACTER SET utf8 COLLATE UTF8_GENERAL_CI ;
Use g00337857abu;
Show tables;


DROP TABLE IF EXISTS invoice;

CREATE TABLE  invoice  (
   invoice_no  int(10)  NOT NULL AUTO_INCREMENT,
   date  date NOT NULL,
   PRIMARY KEY(invoice_no)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


insert into invoice (invoice_no, date) values (1, '2019/02/11');
insert into invoice (invoice_no, date) values (2, '2019/02/19');
insert into invoice (invoice_no, date) values (3, '2019/02/26');
insert into invoice (invoice_no, date) values (4, '2019/02/07');
insert into invoice (invoice_no, date) values (5, '2019/02/15');
insert into invoice (invoice_no, date) values (6, '2019/02/20');
insert into invoice (invoice_no, date) values (7, '2019/02/17');
insert into invoice (invoice_no, date) values (8, '2019/02/16');
insert into invoice (invoice_no, date) values (9, '2019/02/09');
insert into invoice (invoice_no, date) values (10, '2019/02/16');



DROP TABLE IF EXISTS chauffeurs;

CREATE TABLE  chauffeurs  (
   chauffeur_id  int(10) NULL AUTO_INCREMENT,
   fname  varchar(20) NOT NULL,
   lname  varchar(20) NOT NULL,
   phone  int(15) NOT NULL,
   address  varchar(50) NOT NULL,
   city  varchar(15) NOT NULL,
   county  ENUM('Armagh','Carlow','Cavan','Clare','Cork','Derry','Donegal','Down','Dublin','Fermanagh','Galway','Kerry','Kildare','Kilkenny','Laois','Leitrim','Limerick','Longford','Louth','Mayo','Meath','Monaghan','Offaly','Roscommon','Sligo','Tipperary','Tyrone','Waterford','Westmeath','Wexford','Wicklow') NOT NULL,
   PRIMARY KEY (chauffeur_id)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;




DROP TABLE IF EXISTS customers;

CREATE TABLE  customers  (
   customer_id  int(50)  NOT NULL AUTO_INCREMENT,
   fname  varchar(20) NOT NULL,
   lname  varchar(20) NOT NULL,
   dateOfBirth date NOT NULL,
   address  varchar(30) NOT NULL,
   city  varchar(20) NOT NULL,
   county  ENUM('Armagh','Carlow','Cavan','Clare','Cork','Derry','Donegal','Down','Dublin','Fermanagh','Galway','Kerry','Kildare','Kilkenny','Laois','Leitrim','Limerick','Longford','Louth','Mayo','Meath','Monaghan','Offaly','Roscommon','Sligo','Tipperary','Tyrone','Waterford','Westmeath','Wexford','Wicklow') NOT NULL,
   phone  int(10) NOT NULL,
   email  varchar(20) NOT NULL,
   payment_method  ENUM ('Visa', 'Amex', 'Cash', 'American Express', 'Mastercard') NOT NULL,
   status  varchar(10),
   PRIMARY KEY (customer_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;



insert into customers (customer_id, fname, lname,dateOfBirth, address, city, county, phone, email, payment_method, valid_licence, status) values (1, 'Murry', 'Meanwell','1996/03/19', '99 Messerschmidt Terrace', 'CN', 'Dublin', 614237987, 'mmeanwell0@vk.com', 'Amex', 'Yes', 'Approved');
insert into customers (customer_id, fname, lname,dateOfBirth, address, city, county, phone, email, payment_method, valid_licence, status) values (2, 'Phillipp', 'Youell','1995/04/01', '8 Ludington Center', 'FI', 'Donegal', 639868322, 'pyouell1@odnoklassniki.ru', 'Cash', 'Yes', 'Approved');
insert into customers (customer_id, fname, lname,dateOfBirth, address, city, county, phone, email, payment_method, valid_licence, status) values (3, 'Sheffy', 'Huyghe', '1996/05/13','4518 Cherokee Point', 'CU', 'Donegal', 536723289, 'shuyghe2@unblog.fr', 'Visa', 'No', 'Unapproved');
insert into customers (customer_id, fname, lname,dateOfBirth, address, city, county, phone, email, payment_method, valid_licence, status) values (4, 'Willabella', 'Goodricke', '1985/05/29','4 Parkside Plaza', 'TZ', 'Monaghan', 535613089, 'wgoodricke3@ft.com', 'Visa', 'No', 'Unapproved');
insert into customers (customer_id, fname, lname,dateOfBirth, address, city, county, phone, email, payment_method, valid_licence, status) values (5, 'Marcel', 'Harrap', '1966/04/16','595 Thierer Park', 'BR', 'Armagh', 652218720, 'mharrap4@simplemachines.org', 'American Express', 'Yes', 'Approved');
insert into customers (customer_id, fname, lname,dateOfBirth, address, city, county, phone, email, payment_method, valid_licence, status) values (6, 'Mohammed', 'Decayette', '1965/03/14','4 Derek Court', 'ID', 'Longford', 732291765, 'mdecayette5@soundcloud.com', 'Mastercard', 'Yes', 'Approved');
insert into customers (customer_id, fname, lname,dateOfBirth, address, city, county, phone, email, payment_method, valid_licence, status) values (7, 'Annamarie', 'Capaldi', '1978/09/15','9627 Maple Road', 'PH', 'Limerick', 667768503, 'acapaldi6@icio.us', 'Amex', 'Yes', 'Approved');
insert into customers (customer_id, fname, lname,dateOfBirth, address, city, county, phone, email, payment_method, valid_licence, status) values (8, 'Lorain', 'Warcop', '1990/09/18','9 Butternut Place', 'ET', 'Fermanagh', 706068829, 'lwarcop7@admin.ch', 'Amex', 'No', 'Unapproved');
insert into customers (customer_id, fname, lname,dateOfBirth, address, city, county, phone, email, payment_method, valid_licence, status) values (9, 'Rochell', 'O''Hogertie', '1991/02/03','967 Eagan Crossing', 'ID', 'Dublin', 525774883, 'rohogertie8@usatoday.com', 'American Express', 'Yes', 'Approved');
insert into customers (customer_id, fname, lname,dateOfBirth, address, city, county, phone, email, payment_method, valid_licence, status) values (10, 'Eugen', 'Kilmaster', '1980/02/02','0 Heffernan Center', 'PH', 'Kildare', 614171378, 'ekilmaster9@bloglines.com', 'Cash', 'Yes', 'Approved');
insert into customers (customer_id, fname, lname,dateOfBirth, address, city, county, phone, email, payment_method, valid_licence, status) values (11, 'Hendrik', 'Maudlin', '1984/02/01','09188 Cascade Parkway', 'JP', 'Kilkenny', 540520034, 'hmaudlina@google.co.jp', 'Cash', 'Yes', 'Approved');
insert into customers (customer_id, fname, lname,dateOfBirth, address, city, county, phone, email, payment_method, valid_licence, status) values (12, 'Calida', 'Rodbourne', '1981/08/11','2 Marcy Court', 'ID', 'Westmeath', 575906497, 'crodbourneb@forbes.com', 'Mastercard', 'No', 'Unapproved');
insert into customers (customer_id, fname, lname,dateOfBirth, address, city, county, phone, email, payment_method, valid_licence, status) values (13, 'Willow', 'Dunlop', '1971/05/11','8151 Sauthoff Place', 'NL', 'Longford', 689597839, 'wdunlopc@princeton.edu', 'American Express', 'Yes', 'Approved');
insert into customers (customer_id, fname, lname,dateOfBirth, address, city, county, phone, email, payment_method, valid_licence, status) values (14, 'Anjela', 'Large', '1975/06/15','070 Ronald Regan Junction', 'IR', 'Armagh', 789407434, 'alarged@digg.com', 'Visa', 'No', 'Unapproved');
insert into customers (customer_id, fname, lname,dateOfBirth, address, city, county, phone, email, payment_method, valid_licence, status) values (15, 'Joleen', 'Agneau', '1968/12/10','811 Nevada Pass', 'CN', 'Cork', 646755075, 'jagneaue@yolasite.com', 'Amex', 'Yes', 'Approved');
insert into customers (customer_id, fname, lname,dateOfBirth, address, city, county, phone, email, payment_method, valid_licence, status) values (16, 'Abran', 'Bernadot', '1994/11/09','25969 Crowley Junction', 'PA', 'Cavan', 663836895, 'abernadotf@rakuten.co.jp', 'Mastercard', 'No', 'Unapproved');
insert into customers (customer_id, fname, lname,dateOfBirth, address, city, county, phone, email, payment_method, valid_licence, status) values (17, 'Blinnie', 'Mauchline', '1997/07/07','0 Melrose Hill', 'PH', 'Longford', 568099929, 'bmauchlineg@yandex.ru', 'Mastercard', 'No', 'Unapproved');
insert into customers (customer_id, fname, lname,dateOfBirth, address, city, county, phone, email, payment_method, valid_licence, status) values (18, 'Cart', 'Danbrook', '1982/02/20','93800 Luster Lane', 'CN', 'Down', 742262886, 'cdanbrookh@skyrock.com', 'American Express', 'Yes', 'Approved');
insert into customers (customer_id, fname, lname,dateOfBirth, address, city, county, phone, email, payment_method, valid_licence, status) values (19, 'Gay', 'Marousek', '1977/02/21','37 Reindahl Hill', 'CO', 'Louth', 744489842, 'gmarouseki@go.com', 'Visa', 'Yes', 'Approved');
insert into customers (customer_id, fname, lname,dateOfBirth, address, city, county, phone, email, payment_method, valid_licence, status) values (20, 'Amil', 'La Wille', '1996/03/23','5 Eggendart Drive', 'CO', 'Kildare', 730000916, 'alawillej@hibu.com', 'Mastercard', 'Yes', 'Approved');
insert into customers (customer_id, fname, lname,dateOfBirth, address, city, county, phone, email, payment_method, valid_licence, status) values (21, 'Cyndie', 'Tremaine', '1966/04/25','3 Shoshone Park', 'ZA', 'Fermanagh', 622763273, 'ctremainek@ibm.com', 'American Express', 'No', 'Unapproved');
insert into customers (customer_id, fname, lname,dateOfBirth, address, city, county, phone, email, payment_method, valid_licence, status) values (22, 'Ozzy', 'Good', '1969/04/18','76 Lillian Crossing', 'LV', 'Leitrim', 519558890, 'ogoodl@geocities.com', 'Visa', 'Yes', 'Approved');
insert into customers (customer_id, fname, lname,dateOfBirth, address, city, county, phone, email, payment_method, valid_licence, status) values (23, 'Dacia', 'Hardy', '1987/06/15','34 Luster Avenue', 'CN', 'Wexford', 639199541, 'dhardym@acquirethisname.com', 'Visa', 'No', 'Unapproved');
insert into customers (customer_id, fname, lname,dateOfBirth, address, city, county, phone, email, payment_method, valid_licence, status) values (24, 'Phelia', 'Kirkam', '1940/08/17','01248 Dahle Drive', 'ID', 'Clare', 712651763, 'pkirkamn@opera.com', 'Cash', 'Yes', 'Approved');
insert into customers (customer_id, fname, lname,dateOfBirth, address, city, county, phone, email, payment_method, valid_licence, status) values (25, 'Moise', 'Kilmurry', '1980/07/21','58864 Bonner Place', 'PL', 'Roscommon', 763812702, 'mkilmurryo@princeton.edu', 'Mastercard', 'Yes', 'Approved');
insert into customers (customer_id, fname, lname,dateOfBirth, address, city, county, phone, email, payment_method, valid_licence, status) values (26, 'Audie', 'Denman', '1990/06/12','473 Grover Circle', 'CN', 'Antrim', 743361766, 'adenmanp@networkadvertising.org', 'Cash', 'Yes', 'Approved');
insert into customers (customer_id, fname, lname,dateOfBirth, address, city, county, phone, email, payment_method, valid_licence, status) values (27, 'Igor', 'Wringe', '1992/05/11','8661 Mifflin Trail', 'PH', 'Wexford', 529896301, 'iwringeq@w3.org', 'Cash', 'No', 'Unapproved');
insert into customers (customer_id, fname, lname,dateOfBirth, address, city, county, phone, email, payment_method, valid_licence, status) values (28, 'Marian', 'Killock', '1975/04/11','2953 Farragut Park', 'TZ', 'Leitrim', 746171240, 'mkillockr@unblog.fr', 'Visa', 'Yes', 'Approved');
insert into customers (customer_id, fname, lname,dateOfBirth, address, city, county, phone, email, payment_method, valid_licence, status) values (29, 'Emmott', 'Palister', '1954/02/21','47 Morningstar Road', 'RU', 'Waterford', 611959076, 'epalisters@sciencedirect.com', 'Cash', 'Yes', 'Approved');
insert into customers (customer_id, fname, lname,dateOfBirth, address, city, county, phone, email, payment_method, valid_licence, status) values (30, 'Amory', 'Coffin', '1988/02/25','91 Blaine Crossing', 'RU', 'Monaghan', 789249889, 'acoffint@mac.com', 'Mastercard', 'Yes', 'Approved');



DROP TABLE IF EXISTS mechanics;

CREATE TABLE  mechanics  (
   mechanic_id  int(10)  NOT NULL AUTO_INCREMENT,
   fname  varchar(20) NOT NULL,
   lname  varchar(20) NOT NULL,
   PRIMARY KEY (mechanic_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;




DROP TABLE IF EXISTS vehicles;

CREATE TABLE  vehicles (
   vehicle_id  int(10)  NOT NULL AUTO_INCREMENT,
   category ENUM('Sedan','Hatchback','SUV', 'Coupe', 'Crossover') NOT NULL,
   no_of_seats  int(11) NOT NULL,
   brand  varchar(20) NOT NULL,
   model  varchar(20) NOT NULL,
   product_year  int(5) NOT NULL,
   rate_per_day  int(11) NOT NULL,
   PRIMARY KEY (vehicle_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

insert into vehicles (vehicle_id, category, no_of_seats, brand, model, product_year, rate_per_day) values (1, 'SUV', 453742056, 'Honda', 'CR-V', 2000, 230);
insert into vehicles (vehicle_id, category, no_of_seats, brand, model, product_year, rate_per_day) values (2, 'Sedan', 196281065, 'Chevrolet', 'Avalanche', 2012, 100);
insert into vehicles (vehicle_id, category, no_of_seats, brand, model, product_year, rate_per_day) values (3, 'Sedan', 671174279, 'Mercedes-Benz', 'E-Class', 2000, 160);
insert into vehicles (vehicle_id, category, no_of_seats, brand, model, product_year, rate_per_day) values (4, 'Coupe', 788695531, 'Volkswagen', 'Golf', 2012, 110);
insert into vehicles (vehicle_id, category, no_of_seats, brand, model, product_year, rate_per_day) values (5, 'SUV', 773845942, 'Chevrolet', '1500', 2012, 120);
insert into vehicles (vehicle_id, category, no_of_seats, brand, model, product_year, rate_per_day) values (6, 'Hatchback', 537450739, 'Chevrolet', 'Caprice', 2014, 120);
insert into vehicles (vehicle_id, category, no_of_seats, brand, model, product_year, rate_per_day) values (7, 'Hatchback', 689094532, 'Toyota', 'Supra', 2008, 230);
insert into vehicles (vehicle_id, category, no_of_seats, brand, model, product_year, rate_per_day) values (8, 'Hatchback', 573494272, 'Toyota', 'Xtra', 2018, 120);
insert into vehicles (vehicle_id, category, no_of_seats, brand, model, product_year, rate_per_day) values (9, 'SUV', 758628179, 'Oldsmobile', 'Aurora', 2006, 150);
insert into vehicles (vehicle_id, category, no_of_seats, brand, model, product_year, rate_per_day) values (10, 'Crossover', 363309334, 'Volkswagen', 'Passat', 2004, 230);
insert into vehicles (vehicle_id, category, no_of_seats, brand, model, product_year, rate_per_day) values (11, 'Coupe', 610258927, 'Isuzu', 'Space', 2014, 110);
insert into vehicles (vehicle_id, category, no_of_seats, brand, model, product_year, rate_per_day) values (12, 'Hatchback', 721868186, 'Honda', 'Fit', 2011, 230);
insert into vehicles (vehicle_id, category, no_of_seats, brand, model, product_year, rate_per_day) values (13, 'Crossover', 607287551, 'Saturn', 'VUE', 2008, 100);
insert into vehicles (vehicle_id, category, no_of_seats, brand, model, product_year, rate_per_day) values (14, 'Coupe', 364571711, 'Toyota', 'Tacoma Xtra', 2006, 160);
insert into vehicles (vehicle_id, category, no_of_seats, brand, model, product_year, rate_per_day) values (15, 'Crossover', 662262282, 'Hyundai', 'Excel', 2012, 140);
insert into vehicles (vehicle_id, category, no_of_seats, brand, model, product_year, rate_per_day) values (16, 'Hatchback', 380739699, 'Ford', 'Expedition', 2016, 120);
insert into vehicles (vehicle_id, category, no_of_seats, brand, model, product_year, rate_per_day) values (17, 'Sedan', 418928952, 'Mercedes-Benz', 'SL-Class', 2019, 100);
insert into vehicles (vehicle_id, category, no_of_seats, brand, model, product_year, rate_per_day) values (18, 'Crossover', 567185211, 'Mazda', 'B-Series Plus', 2012, 150);
insert into vehicles (vehicle_id, category, no_of_seats, brand, model, product_year, rate_per_day) values (19, 'Coupe', 330681193, 'Eagle', 'Vision', 2011, 220);
insert into vehicles (vehicle_id, category, no_of_seats, brand, model, product_year, rate_per_day) values (20, 'Sedan', 537744150, 'Mazda', 'MPV', 2014, 100);
insert into vehicles (vehicle_id, category, no_of_seats, brand, model, product_year, rate_per_day) values (21, 'Sedan', 158332730, 'GMC', 'Yukon', 2013, 100);
insert into vehicles (vehicle_id, category, no_of_seats, brand, model, product_year, rate_per_day) values (22, 'SUV', 445878044, 'Mitsubishi', 'Lancer', 2013, 220);
insert into vehicles (vehicle_id, category, no_of_seats, brand, model, product_year, rate_per_day) values (23, 'Crossover', 732614972, 'Chevrolet', 'Blazer', 2013, 160);
insert into vehicles (vehicle_id, category, no_of_seats, brand, model, product_year, rate_per_day) values (24, 'Crossover', 650282220, 'Buick', 'LaCrosse', 2008, 230);
insert into vehicles (vehicle_id, category, no_of_seats, brand, model, product_year, rate_per_day) values (25, 'Sedan', 698142686, 'Volkswagen', 'Routan', 2009, 150);
insert into vehicles (vehicle_id, category, no_of_seats, brand, model, product_year, rate_per_day) values (26, 'Coupe', 107564855, 'Jaguar', 'S-Type', 2017, 230);
insert into vehicles (vehicle_id, category, no_of_seats, brand, model, product_year, rate_per_day) values (27, 'SUV', 731578224, 'Suzuki', 'Swift', 2017, 110);
insert into vehicles (vehicle_id, category, no_of_seats, brand, model, product_year, rate_per_day) values (28, 'Coupe', 297823278, 'Pontiac', 'G5', 2007, 150);

DROP TABLE IF EXISTS inspections;

CREATE TABLE  inspections  (
   inspection_id  int(10)  NOT NULL AUTO_INCREMENT,
   inspection_date  date NOT NULL,
   vehicle_id  int(10) NOT NULL,
   problem  varchar(50) NOT NULL,
   repair_complete  ENUM('Yes','No') NOT NULL,
   mechanic_id  int(10)  NOT NULL,
   PRIMARY KEY(inspection_id),
   KEY mechanic_idfk1 (mechanic_id),
   KEY vehicle_idfk2 (vehicle_id),
   CONSTRAINT vehicle_idfk2 FOREIGN KEY (vehicle_id) REFERENCES vehicles (vehicle_id),
   CONSTRAINT mechanic_idfk1 FOREIGN KEY (mechanic_id) REFERENCES mechanics (mechanic_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

insert into inspections (inspection_id, inspection_date, vehicle_id, problem, repair_complete, mechanic_id) values (1, '2019/02/15', 1, 'Brake lights not working', 'Yes', 1);
insert into inspections (inspection_id, inspection_date, vehicle_id, problem, repair_complete, mechanic_id) values (2, '2019/02/12', 2, 'Oil change', 'No', 2);
insert into inspections (inspection_id, inspection_date, vehicle_id, problem, repair_complete, mechanic_id) values (3, '2019/03/02', 3, 'Brake lights not working', 'Yes', 3);
insert into inspections (inspection_id, inspection_date, vehicle_id, problem, repair_complete, mechanic_id) values (4, '2019/02/16', 4, 'Oil change', 'Yes', 4);
insert into inspections (inspection_id, inspection_date, vehicle_id, problem, repair_complete, mechanic_id) values (5, '2019/02/25', 5, 'Indicators not working', 'Yes', 5);
insert into inspections (inspection_id, inspection_date, vehicle_id, problem, repair_complete, mechanic_id) values (6, '2019/02/20', 6, 'Brake lights not working', 'No', 6);
insert into inspections (inspection_id, inspection_date, vehicle_id, problem, repair_complete, mechanic_id) values (7, '2019/02/01', 7, 'Indicators not working', 'No', 7);
insert into inspections (inspection_id, inspection_date, vehicle_id, problem, repair_complete, mechanic_id) values (8, '2019/03/12', 8, 'Windscreen fluid', 'Yes', 8);
insert into inspections (inspection_id, inspection_date, vehicle_id, problem, repair_complete, mechanic_id) values (9, '2019/02/27', 9, 'Indicators not working', 'Yes', 9);
insert into inspections (inspection_id, inspection_date, vehicle_id, problem, repair_complete, mechanic_id) values (10, '2019/02/22', 10, 'Brake lights not working', 'Yes', 10);




DROP TABLE IF EXISTS payment_details;

CREATE TABLE  payment_details  (
   card_no  int(8) NOT NULL,
   customer_id  int(50)  NOT NULL AUTO_INCREMENT,
   CVV  int(3) NOT NULL,
   card_type  ENUM ('Visa', 'Amex', 'American Express', 'Mastercard') NOT NULL,
   expiry_date  DATE NOT NULL,
   PRIMARY KEY(card_no),
   KEY customer_idfk1 (customer_id),
   CONSTRAINT customer_idfk1 FOREIGN KEY (customer_id) REFERENCES customers (customer_id) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

insert into payment_details (card_no, customer_id, CVV, card_type, expiry_date) values (35190499, 1, 931, 'American Express', '2021-06-13');
insert into payment_details (card_no, customer_id, CVV, card_type, expiry_date) values (63054139, 2, 342, 'American Express', '2022-04-07');
insert into payment_details (card_no, customer_id, CVV, card_type, expiry_date) values (63013742, 3, 650, 'Amex', '2022-06-15');
insert into payment_details (card_no, customer_id, CVV, card_type, expiry_date) values (27873429, 4, 948, 'American Express', '2021-07-15');
insert into payment_details (card_no, customer_id, CVV, card_type, expiry_date) values (45492485, 5, 935, 'American Express', '2023-04-24');
insert into payment_details (card_no, customer_id, CVV, card_type, expiry_date) values (46495832, 6, 202, 'Amex', '2022-10-23');
insert into payment_details (card_no, customer_id, CVV, card_type, expiry_date) values (30516751, 7, 388, 'American Express', '2022-04-27');
insert into payment_details (card_no, customer_id, CVV, card_type, expiry_date) values (21698657, 8, 229, 'American Express', '2021-08-20');
insert into payment_details (card_no, customer_id, CVV, card_type, expiry_date) values (25473375, 9, 748, 'Visa', '2022-09-05');
insert into payment_details (card_no, customer_id, CVV, card_type, expiry_date) values (14747537, 10, 419, 'American Express', '2022-05-22');
insert into payment_details (card_no, customer_id, CVV, card_type, expiry_date) values (23744586, 11, 208, 'Mastercard', '2023-04-13');
insert into payment_details (card_no, customer_id, CVV, card_type, expiry_date) values (51349308, 12, 870, 'Visa', '2022-05-16');
insert into payment_details (card_no, customer_id, CVV, card_type, expiry_date) values (27534873, 13, 942, 'Amex', '2023-05-20');
insert into payment_details (card_no, customer_id, CVV, card_type, expiry_date) values (49592792, 14, 797, 'American Express', '2021-07-05');
insert into payment_details (card_no, customer_id, CVV, card_type, expiry_date) values (42218345, 15, 990, 'Mastercard', '2022-01-01');
insert into payment_details (card_no, customer_id, CVV, card_type, expiry_date) values (55037452, 16, 529, 'Visa', '2022-03-20');
insert into payment_details (card_no, customer_id, CVV, card_type, expiry_date) values (52641261, 17, 712, 'Mastercard', '2022-12-01');
insert into payment_details (card_no, customer_id, CVV, card_type, expiry_date) values (54252751, 18, 386, 'Visa', '2022-03-23');
insert into payment_details (card_no, customer_id, CVV, card_type, expiry_date) values (38754112, 19, 139, 'Visa', '2023-04-10');
insert into payment_details (card_no, customer_id, CVV, card_type, expiry_date) values (27544376, 20, 533, 'American Express', '2023-01-03');
insert into payment_details (card_no, customer_id, CVV, card_type, expiry_date) values (35786440, 21, 690, 'Amex', '2022-02-08');
insert into payment_details (card_no, customer_id, CVV, card_type, expiry_date) values (26628630, 22, 320, 'American Express', '2021-06-03');
insert into payment_details (card_no, customer_id, CVV, card_type, expiry_date) values (35055457, 23, 862, 'Visa', '2022-06-07');
insert into payment_details (card_no, customer_id, CVV, card_type, expiry_date) values (25999601, 24, 682, 'Visa', '2021-06-13');
insert into payment_details (card_no, customer_id, CVV, card_type, expiry_date) values (51688231, 25, 242, 'American Express', '2022-05-26');
insert into payment_details (card_no, customer_id, CVV, card_type, expiry_date) values (48934493, 26, 530, 'Mastercard', '2022-06-02');
insert into payment_details (card_no, customer_id, CVV, card_type, expiry_date) values (28729338, 27, 109, 'Visa', '2023-02-21');
insert into payment_details (card_no, customer_id, CVV, card_type, expiry_date) values (55502111, 28, 795, 'American Express', '2021-10-22');
insert into payment_details (card_no, customer_id, CVV, card_type, expiry_date) values (30664349, 29, 338, 'Mastercard', '2023-01-31');
insert into payment_details (card_no, customer_id, CVV, card_type, expiry_date) values (43536088, 30, 245, 'American Express', '2022-01-08');



DROP TABLE IF EXISTS vehicle_collections;

CREATE TABLE  vehicle_collections  (
   collection_id  int(10)NOT NULL AUTO_INCREMENT,
   vehicle_id  int(10)  NOT NULL ,
   collection_date  date NOT NULL,
   return_date  date NOT NULL,
   mileage_before  int(10) NOT NULL,
   mileage_after  int(10) NOT NULL,
   duration  int(5) NOT NULL,
   PRIMARY KEY (collection_id),
   KEY vehicle_idfk1 (vehicle_id),
   CONSTRAINT vehicle_idfk1 FOREIGN KEY (vehicle_id) REFERENCES vehicles (vehicle_id) 
   ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

insert into vehicle_collections (collection_id, vehicle_id, collection_date, return_date, mileage_before, mileage_after, duration) values (1, 1, '2018/01/08', '2018/01/15', 20000, 21500, 7);
insert into vehicle_collections (collection_id, vehicle_id, collection_date, return_date, mileage_before, mileage_after, duration) values (2, 2, '2018/01/22', '2018/01/28', 35600, 37200, 6);
insert into vehicle_collections (collection_id, vehicle_id, collection_date, return_date, mileage_before, mileage_after, duration) values (3, 3, '2018/01/26', '2018/02/01', 14000, 16600, 6);
insert into vehicle_collections (collection_id, vehicle_id, collection_date, return_date, mileage_before, mileage_after, duration) values (4, 4, '2018/02/12', '2018/02/16', 25000, 29400, 4);
insert into vehicle_collections (collection_id, vehicle_id, collection_date, return_date, mileage_before, mileage_after, duration) values (5, 5, '2018/02/14', '2018/03/17', 32200, 35550, 3);




DROP TABLE IF EXISTS bookings;

   CREATE TABLE  bookings  (
   booking_id  int(50)  NOT NULL AUTO_INCREMENT,
   booking_date  date NOT NULL,
   start_date  date NOT NULL,
   end_date  date NOT NULL,
   invoice_no int(10)  NOT NULL ,
   chauffeur_id int(10) NULL,
   vehicle_id int(10)  NOT NULL ,
   customer_id int(50) NOT NULL ,
   chauffeur_req ENUM('Yes','No') NOT NULL,
   special_instructions varchar(255) NOT NULL,
   PRIMARY KEY (booking_id),
   KEY invoice_nofk2 (invoice_no),
   KEY chauffeur_idfk1 (chauffeur_id),
   KEY customer_idfk2 (customer_id),
   KEY vehicle_idfk2 (vehicle_id),
   CONSTRAINT invoice_nofk1 FOREIGN KEY (invoice_no) REFERENCES invoice (invoice_no),
   CONSTRAINT chauffeur_idfk2 FOREIGN KEY (chauffeur_id) REFERENCES chauffeurs (chauffeur_id),
   CONSTRAINT customer_idfk3 FOREIGN KEY (customer_id) REFERENCES customers (customer_id), 
   CONSTRAINT vehicle_idfk3 FOREIGN KEY (vehicle_id) REFERENCES vehicles (vehicle_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


insert into bookings (booking_id, booking_date, start_date, end_date, invoice_no, chauffeur_id, vehicle_id, customer_id, chauffeur_req,special_instructions) values (1, '2019/02/26', '2019/02/28', '2019/03/01', 1, 1, 1, 1, 'Yes', 'Be a bit early');
insert into bookings (booking_id, booking_date, start_date, end_date, invoice_no, chauffeur_id, vehicle_id, customer_id, chauffeur_req,special_instructions) values (2, '2019/02/28', '2019/02/28', '2019/03/03', 2, NULL, 2, 2, 'No','Please have some water');
insert into bookings (booking_id, booking_date, start_date, end_date, invoice_no, chauffeur_id, vehicle_id, customer_id, chauffeur_req,special_instructions) values (3, '2019/03/01', '2019/03/02', '2019/03/05', 3, NULL, 3, 3, 'No','Drive slow, children in the car');
insert into bookings (booking_id, booking_date, start_date, end_date, invoice_no, chauffeur_id, vehicle_id, customer_id, chauffeur_req,special_instructions) values (4, '2019/03/04', '2019/03/06', '2019/03/10', 4, 4, 4, 4, 'Yes','Please be silent while driving');
insert into bookings (booking_id, booking_date, start_date, end_date, invoice_no, chauffeur_id, vehicle_id, customer_id, chauffeur_req,special_instructions) values (5, '2019/03/08', '2019/03/09', '2019/03/13', 5, NULL, 5, 5, 'No','Need to be exactly on time');
insert into bookings (booking_id, booking_date, start_date, end_date, invoice_no, chauffeur_id, vehicle_id, customer_id, chauffeur_req,special_instructions) values (6, '2019/04/03', '2019/04/04', '2019/04/06', 6, 6, 6, 6, 'Yes','Children onboard, please drive slow');
insert into bookings (booking_id, booking_date, start_date, end_date, invoice_no, chauffeur_id, vehicle_id, customer_id, chauffeur_req,special_instructions) values (7, '2019/04/05', '2019/04/07', '2019/03/10', 7, NULL, 7, 7, 'No','Arrive 5 minutes early');

0 个答案:

没有答案