Dbms SQL
Dbms SQL
CREATE TABLE cars ( VIN VARCHAR(7) NOT NULL, car_desc VARCHAR(255), color VARCHAR(45), brand
VARCHAR(45), model VARCHAR(45), cat_id INT, purch_date DATE, PRIMARY KEY (VIN), FOREIGN KEY
(cat_id) REFERENCES categories(cat_id) );
CREATE TABLE locations ( loc_id INT NOT NULL AUTO_INCREMENT, street VARCHAR(45), streetno
VARCHAR(10), -- We put it Varchar to account for cases like "34A Houston street" city VARCHAR(45),
lstate VARCHAR(45), lcountry VARCHAR(45), PRIMARY KEY (loc_id) );
CREATE TABLE phones ( phone_id INT NOT NULL AUTO_INCREMENT, phone_no VARCHAR(15), loc_id
INT NOT NULL, PRIMARY KEY (phone_id), FOREIGN KEY (loc_id) REFERENCES locations(loc_id) );
CREATE TABLE customers ( id INT NOT NULL AUTO_INCREMENT, first_name VARCHAR(45), last_name
VARCHAR(45), email VARCHAR(45), ssn VARCHAR(11) NOT NULL, mobile VARCHAR(15), state_abbrev
VARCHAR(45), state_name VARCHAR(45), country VARCHAR(45), PRIMARY KEY (id) );
CREATE TABLE reservations ( reservation_id INT NOT NULL AUTO_INCREMENT, VIN VARCHAR(7) NOT
NULL, cust_id INT NOT NULL, amount DECIMAL(6,2), p_loc INT NOT NULL,p_date DATE,r_loc INT NOT
NULL,r_date DATE, PRIMARY KEY (reservation_id), FOREIGN KEY (VIN) REFERENCES cars(VIN), FOREIGN
KEY (cust_id) REFERENCES customers(id), FOREIGN KEY (p_loc) REFERENCES locations(loc_id),
FOREIGN KEY (r_loc) REFERENCES locations(loc_id) );)
INSERT INTO categories (cat_label, cat_desc) VALUES ("Compact", "Sedan-type car with 5 doors"),
("Convertible", "The roof of the car is retractable, hard-top or soft-top"), ("Jeep", "4X4, tall vehicle,
usually suitable for off-road conditions"), ("Luxury", "Long town car, usually used for professional
chauffer services"), ("SUV", "A mix between a sedan and a Jeep, medium-to-tall height, suitable for
both city and off-road conditions"), ("Hatchback", "Small car, with a flat back-side, usually suitable for
low consumption and convenient parking"), ("Pickup", "Pickup truck, with a large open or closed
trunk, suitable for personal or professional use");
INSERT INTO cars (VIN, car_desc, color, brand, model, cat_id, purch_date) VALUES ("ZTY4567",
"Convertible with hardtop, leather seats and CD player", "Silver", "Mercedes-Benz", "SLK200", 2, "2007-
02-08"), ("ATB2646", "Professional and good-looking, full-extra", "Blue", "BMW", "160i", 1, "2012-08-
01"), ("IKP3998", "Stylish and eye-catching, with GPS", "Red", "Suzuki", "Swift", 6, "2013-12-09"),
("IKA8788", "Low consumption and convenience, hybrid, with GPS", "Silver", "Toyota", "Auris", 6,
"2016-11-01"), ("IBN1220", "Luxurious and business-ready, leather seats, cruise control", "Black",
"BMW", "520i", 1, "2005-03-10"), ("IPK1002", "Easy handling, automatic, parking assistant", "Blue",
"Opel", "Corsa", 6, "2011-11-17"), ("KMX3344", "Eye-catching and elegant, 360 parking assistant,
bluetooth", "White", "Nissan", "Juke", 5, "2016-02-01"), ("POO9821", "Convenience and off-road
capabilities, leather seats, CD player", "Orange", "Nissan", "Navara", 7, "2014-10-23"), ("IBN5786",
"Luxurious and business-ready", "Black", "Mercedes-Benz", "S500", 4, "2010-08-06"), ("YKP3668",
"Hybrid, convenience, parking assistant, bluetooth", "Red", "Toyota", "Auris", 6, "2017-06-06"),
("ZMP1210", "Low consumption with 5 doors, CD player", "Red", "Toyota", "Yaris", 6, "2013-01-10"),
("IKP2221", "Parking assistant, 5 doors, automatic", "Red", "Opel", "Corsa", 6, "2011-08-12"),
("IBT4312", "4X4 with up to 9 seats and off-road capatilities", "Red", "Jeep", "Grand Cherokee", 3,
"2009-01-10"), ("PIK5665", "Limousine with up to 9 luxurious leather seats and bar", "Red", "Lincoln",
"Town Car", 4, "2004-04-17");
INSERT INTO phones (phone_no, loc_id) VALUES ("+302107265432", 4), ("+302310432751", 5),
("+145678987653", 1), ("+145678987654", 1), ("+442112368123", 2), ("+442112368124", 2),
("+507621848001", 3), ("+302107265433", 4), ("+302310432750", 5), ("+391329845421", 6),
("+421237898124", 7), ("+317901663925", 8), ("+206981797677", 9), ("+106541672231", 10),
("+106541672232", 10);
INSERT INTO customers (first_name, last_name, email, ssn, mobile, state_abbrev, state_name,
country) VALUES ("Dedric","Purdy","[email protected]","737-73-2213","022-280-
370972","MI"," Michigan","Cyprus"), ("Gayle","Ferry","[email protected]","931-13-2414","1-574-
831-0280","NC","NorthCar olina","Christmas Island"),
("Romaine","Gutkowski","[email protected]","323-33-2233","+85(1)810596397","MIS",
"Mississippi","Cook Islands"), ("Selena","Dach","[email protected]","862-26-2682","(787)403-
08989","MA","Massach usetts","Palau"), ("Dayana","Keefe","[email protected]","646-64-
4664","04551803452","HAW","Hawaii"," Montserrat"),
("Ryley","Weimann","[email protected]","261-16-6212","308-383-911579","FL
O","Florida","Cook Islands"), ("Lois","Frami","[email protected]","713-15-2204","324-017-
982855","MAR","Marylan d","Singapore"), ("Kali","Monahan","[email protected]","737-73-
1234","760=111-3122","TEN","Tenne ssee","Peru"),
("Ransom","Brown","[email protected]","843-34-3821","858.373.739295","WYO","Wyomi
ng","Cambodia"), ("Jensen","Haag","[email protected]","907-79-
0891","+07(4)621652845","T EX","Texas","USA"), ("Jeramy","Reilly","[email protected]","725-
52-2516","399.543.013362","MIS","M ississippi","USA"), ("Edgardo","Wolf","[email protected]","784-
48-8471","(827)905-7283","NEV","Nevada","L ebanon"),
("Jalen","Spencer","[email protected]","910-21-1099","(365)321-0966","M
IN","Minnesota","USA"), ("Dimitri","Kon","[email protected]","977-79-9905","653-476-
5758","OKL","Ok lahoma","USA"), ("Lester","Volkman","[email protected]","717-66-
567","933-195-4371","GEO","Georgia","USA");
INSERT INTO reservations (amount, p_date, r_date, p_loc, r_loc, VIN, cust_id) VALUES ("132.23",
"2015-05-02", "2015-10-10", 1, 1, "ZTY4567", 2), ("111.11", "2015-05-03", "2015-05-04", 2, 2, "IKA8788",
8), ("222.22", "2015-05-04", "2015-05-05", 3, 3, "ATB2646", 8), ("333.33", "2015-05-06", "2015-05-06", 1,
2, "IPK1002", 9), ("444.44", "2015-05-07", "2015-05-08", 3, 1, "ZTY4567", 11), ("300.20", "2015-03-14",
"2015-03-14", 10, 9, "IKP3998", 7), ("29.10", "2015-05-20", "2015-05-22", 2, 3, "KMX3344", 15),
("1000.00", "2015-05-20", "2015-07-29", 4, 4, "YKP3668", 14), ("69.90", "2015-03-08", "2015-03-22", 8, 5,
"KMX3344", 10), ("239.25", "2017-12-31", "2018-01-10", 6, 6, "IPK1002", 2), ("41.22", "2014-01-22",
"2014-01-23", 5, 2, "ZTY4567", 1), ("22.33", "2015-05-09", "2015-05-31", 3, 7, "IKA8788", 3), ("38.26",
"2015-10-13", "2015-10-15", 7, 7, "KMX3344", 6), ("77.88", "2015-10-22", "2015-10-27", 9, 1, "IBN1220",
5), ("99.66", "2015-05-23", "2015-05-29", 2, 5, "IKP3998", 13), ("34.12", "2015-10-24", "2015-10-28", 8, 1,
"IPK1002", 4), ("667.99", "2015-03-19", "2015-03-20", 5, 7, "ZMP1210", 7), ("156.01", "2014-08-06",
"2014-08-12", 1, 2, "POO9821", 12), ("39.29", "2015-01-07", "2015-01-11", 2, 8, "IKA8788", 11), ("45.55",
"2015-01-08", "2015-01-10", 2, 2, "IKA8788", 9), ("21.18", "2015-03-02", "2015-03-04", 3, 4, "IBN5786", 2),
("109.57", "2015-08-01", "2015-08-15", 3, 3, "IBN5786", 15), ("124.56", "2014-05-15", "2014-05-23", 4, 4,
"IBT4312", 6), ("543.22", "2014-05-24", "2014-05-08", 4, 5, "ZTY4567", 7), ("578.34", "2014-10-01",
"2014-10-25", 4,8, "ZTY4567", 8), ("199.99", "2014-04-06", "2018-04-15", 5, 5, "ZMP1210", 2), ("201.02",
"2014-04-14", "2014-04-20", 5, 5, "IBN1220", 1), ("202.03", "2014-10-08", "2014-10-19", 5, 4, "IBN1220",
13), ("68.71", "2018-07-11", "2018-07-14", 6, 6, "ATB2646", 11), ("78.81", "2015-08-25", "2015-08-30", 6,
7, "ATB2646", 5), ("88.91", "2014-10-02", "2014-10-07", 7, 7, "KMX3344", 8), ("15.05", "2015-07-08",
"2010-07-08", 8, 8, "IPK1002", 11), ("14.13", "2015-06-10", "2015-06-11", 9, 9, "IKP3998", 2), ("19.20",
"2015-06-30", "2015-07-01", 9, 9, "IKP2221", 3), ("248.84", "2015-04-16", "2015-04-29", 9,10, "IKP2221",
4), ("76.67", "2015-04-17", "2015-04-23", 9, 7, "IKP3998", 5), ("129.99", "2015-04-01", "2015-04-10", 9, 9,
"IKP3998", 6), ("312.21", "2014-05-26", "2014-05-06", 10, 10, "KMX3344", 15), ("54.45", "2015-05-08",
"2014-05-10", 10,10, "PIK5665", 14), ("34.45", "2014-08-09", "2014-08-11", 9,9, "PIK5665", 14), ("23.19",
"2014-08-10", "2014-05-12", 7,7, "PIK5665", 13), ("41.68", "2014-08-14", "2014-08-17", 6,6, "PIK5665",
14);