Files
DataClaw/examples/Car_Database.db
T

232 lines
64 KiB
Plaintext
Raw Normal View History

2026-03-15 20:48:40 +08:00
SQLite format 3@ -ùˆûû ê
 ÔÂì e Wƒtriggervalidate_email_before_insert_customerCustomersCREATE TRIGGER validate_email_before_insert_customer
BEFORE INSERT ON Customers
BEGIN
SELECT CASE
WHEN NEW.email NOT LIKE '%_@__%.__%' THEN
RAISE (ABORT,'Invalid email address')
END;
ENDO?„MtriggerOption_Set_Model_RelationCar_VinsCREATE TRIGGER Option_Set_Model_Relation
BEFORE INSERT ON Car_Vins
BEGIN
SELECT CASE
WHEN(
SELECT CO.model_id
FROM Car_Options as CO
WHERE
NEW.option_set_id = CO.option_set_id and
NEW.model_id = CO.model_id)
THEN RAISE(FAIL, "Invlalid Option Set")
END;
END$tableDealersDealersCREATE TABLE Dealers (
dealer_id INTEGER PRIMARY KEY AUTOINCREMENT,
dealer_name VARCHAR(50) NOT NULL,
dealer_address VARCHAR(100)
)YtableBrandsBrandsCREATE TABLE Brands(
brand_id INTEGER PRIMARY KEY AUTOINCREMENT,
brand_name VARCHAR(50) NOT NUll
)\//„gtableManufacture_PlantManufacture_Plant CREATE TABLE Manufacture_Plant(
manufacture_plant_id INTEGER PRIMARY KEY AUTOINCREMENT,
plant_name VARCHAR(50) NOT NULL,
plant_type VARCHAR (7) CHECK (plant_type="Assembly" or plant_type="Parts"),
plant_location VARCHAR(100),
company_owned INTEGER CHECK(company_owned=0 or company_owned=1)

tableCar_PartsCar_PartsCREATE TABLE Car_Parts(
part_id INTEGER PRIMARY KEY AUTOINCREMENT,
part_name VARCHAR(100) NOT NULL,
manufacture_plant_id INTEGER NOT NULL,
manufacture_start_date DATE NOT NUll,
manufacture_end_date DATE,
part_recall INTEGER DEFAULT 0 CHECK (part_recall = 0 or part_recall = 1),
FOREIGN KEY (manufacture_plant_id) REFERENCES Manufacture_Plant(manufacture_plant_id)
)7 K%indexsqlite_autoindex_Dealer_Brand_1Dealer_Brand
 %%ƒatableDealer_BrandDealer_Brand CREATE TABLE Dealer_Brand(
dealer_id INTEGER NOT NULL,
brand_id INTEGER NOT NULL,
FOREIGN KEY (dealer_id) REFERENCES Dealers(dealer_id),
FOREIGN KEY (brand_id) REFERENCES Brands(brand_id),
PRIMARY KEY (dealer_id, brand_id)
)C W1indexsqlite_autoindex_Customer_Ownership_1Customer_Ownership
ƒN11†GtableCustomer_OwnershipCustomer_Ownership CREATE TABLE Customer_Ownership(
customer_id INTEGER NOT NULL,
vin INTEGER NOT NULL,
purchase_date DATE NOT NULL,
purchase_price INTEGER NOT NULL,
warantee_expire_date DATE,
dealer_id INTEGER NOT NULL,
FOREIGN KEY (customer_id) REFERENCES Customers(customer_id),
FOREIGN KEY (vin) REFERENCES Car_Vins(vin),
FOREIGN KEY (dealer_id) REFERENCES Dealers(dealer_id)
PRIMARY KEY (customer_id, vin)
)wƒItableModelsModelsCREATE TABLE Models(
model_id INTEGER PRIMARY KEY AUTOINCREMENT,
model_name VARCHAR(50) NOT NULL,
model_base_price INTEGER NOT NULL,
brand_id INTEGER NOT NULL,
FOREIGN KEY (brand_id) REFERENCES Brands(brand_id)
)l…+tableCar_VinsCar_VinsCREATE TABLE Car_Vins(
vin INTEGER PRIMARY KEY AUTOINCREMENT,
option_set_id INTEGER NOT NULL,
manufactured_date DATE NOT NULL,
manufactured_plant_id INTEGER NOT NULL,
FOREIGN KEY (manufactured_plant_id) REFERENCES Manufacture_Plant(manufactured_plant_id),
FOREIGN KEY (option_set_id) REFERENCES Car_Options(option_set_id)
)P++Ytablesqlite_sequencesqlite_sequenceCREATE TABLE sqlite_sequence(name,seq)XtableCustomersCustomersCREATE TABLE Customers(
customer_id INTEGER PRIMARY KEY AUTOINCREMENT,
first_name VARCHAR(50) NOT NULL,
last_name VARCHAR(50) NOT NULL,
gender STRING CHECK(gender = "Male" or gender = "Female"),
household_income INTEGER,
birthdate DATE NOT NULL,
phone_number INTEGER NOT NULL,
email VARCHAR(1
}ƒI
É}J !CJessicaParkerFemaleÔÀ1989-06-29ýë˜JennyFromThePark@mymail.com? !1MinnieMouseFemale
@1950-03-01Á—aëMinnieMe@gmail.com= !/PitbullPerezMaleO€1985-12-01Ök”CPitbull@ymail.com8 !1JacobWongMale]À1992-02-20~õZWonTon@hotmail.com= !+MariaSwabotaFemaleê`1980-06-15ëGMaria@Gmail.com< !-JeremyJacobsMaleÔÀ1990-12-12#]Jeremy@Gmail.com
óçÛ
Models
Brands Dealers
˜ëÖÁ¬˜ !2013-06-22!
2013-03-04!
2014-11-14!2016-09-19!2017-02-20
mÛµmÙÙÙÙ#!7Joes Autos123 Abc Lane Virginiao!7Joes Autos123 Abc Lane VirginiaJ!7Joes Autos123 Abc Lane Virginia%!7Joes Autos123 Abc Lane Virginia!!3Priority Z8675309 Jessies Mom#!7Priority Y404 Address Not Found$!9Priority X999 N
á'#!!2WD Chassis2005-12-202017-11-01'#!!4WD Chassis2000-08-292017-05-12%! !!Bose Audio2014-08-022015-03-12*)!!Jetrag 6 Speed2012-02-112013-08-12'#!!2.4L Engine2012-08-122013-08-12'#!!3.0L Engine2012-07-102017-02-20&# !!2.6L Engine2012-08-122013-08-12
±íáÖʾ
BoujieeFerrariyYellownSupremeb)Cover Squirrel Freshest
Boujiee
Ferrari Yellow
Supreme)Cover Squirrel
ÞíØÃ¥vgSE,üíÞ
Barsˆ¸
Beats]ÀToo Muchˆ¸
Extrau0
F40†  )F12 Berlinetta­° 450
LaFerrarièH
GreenBh Blue.àOrange:˜T-ShirtixSweatera¨ HatUð% The Red HeadqH% The Brunettea¨! The BlondeYØ
Xß½šyX
ÛÛêâòú  
     
ŸûôæíÇÞÖί¿·§Ÿ
  
     

²êÒ¼¨t^G2òÞË´žˆqT@%
ó
Ý
Ê
²  MagentaÈ Red  Purple< Green°  # Transparentœ@  # Ultravioleta¨  Nyan? % Glitter BomB T Pretty˜ Whiteü Black Yellow   RedÜ
 BlueÐ BlackL  
GreenYØ
 Blue,$  Red'  
Purple Ä CyanX 'Birthday Cake Ä Sky ¸  Red   GreenL Yellow° BlueÐ
äì¥S ê
 ÔÂìì e Wƒtriggervalidate_email_before_insert_customerCustomersCREATE TRIGGER validate_email_before_insert_customer
BEFORE INSERT ON Customers
BEGIN
SELECT CASE
WHEN NEW.email NOT LIKE '%_@__%.__%' THEN
RAISE (ABORT,'Invalid email address')
END;
ENDO?„MtriggerOption_Set_Model_RelationCar_VinsCREATE TRIGGER Option_Set_Model_Relation
BEFORE INSERT ON Car_Vins
BEGIN
SELECT CASE
WHEN(
SELECT CO.model_id
FROM Car_Options as CO
WHERE
NEW.option_set_id = CO.option_set_id and
NEW.model_id = CO.model_id)
THEN RAISE(FAIL, "Invlalid Option Set")
END;
END$tableDealersDealersCREATE TABLE Dealers (
dealer_id INTEGER PRIMARY KEY AUTOINCREMENT,
dealer_name VARCHAR(50) NOT NULL,
dealer_address VARCHAR(100)
)YtableBrandsBrandsCREATE TABLE Brands(
brand_id INTEGER PRIMARY KEY AUTOINCREMENT,
brand_name VARCHAR(50) NOT NUll
)\//„gtableManufacture_PlantManufacture_Plant CREATE TABLE Manufacture_Plant(
manufacture_plant_id INTEGER PRIMARY KEY AUTOINCREMENT,
plant_name VARCHAR(50) NOT NULL,
plant_type VARCHAR (7) CHECK (plant_type="Assembly" or plant_type="Parts"),
plant_location VARCHAR(100),
company_owned INTEGER CHECK(company_owned=0 or company_owned=1)

tableCar_PartsCar_PartsCREATE TABLE Car_Parts(
part_id INTEGER PRIMARY KEY AUTOINCREMENT,
part_name VARCHAR(100) NOT NULL,
manufacture_plant_id INTEGER NOT NULL,
manufacture_start_date DATE NOT NUll,
manufacture_end_date DATE,
part_recall INTEGER DEFAULT 0 CHECK (part_recall = 0 or part_recall = 1),
FOREIGN KEY (manufacture_plant_id) REFERENCES Manufacture_Plant(manufacture_plant_id)
)7 K%indexsqlite_autoindex_Dealer_Brand_1Dealer_Brand
 %%ƒatableDealer_BrandDealer_Brand CREATE TABLE Dealer_Brand(
dealer_id INTEGER NOT NULL,
brand_id INTEGER NOT NULL,
FOREIGN KEY (dealer_id) REFERENCES Dealers(dealer_id),
FOREIGN KEY (brand_id) REFERENCES Brands(brand_id),
PRIMARY KEY (dealer_id, brand_id)
)C W1indexsqlite_autoindex_Customer_Ownership_1Customer_Ownership
ƒN11†GtableCustomer_OwnershipCustomer_Ownership CREATE TABLE Customer_Ownership(
customer_id INTEGER NOT NULL,
vin INTEGER NOT NULL,
purchase_date DATE NOT NULL,
purchase_price INTEGER NOT NULL,
warantee_expire_date DATE,
dealer_id INTEGER NOT NULL,
FOREIGN KEY (customer_id) REFERENCES Customers(customer_id),
FOREIGN KEY (vin) REFERENCES Car_Vins(vin),
FOREIGN KEY (dealer_id) REFERENCES Dealers(dealer_id)
PRIMARY KEY (customer_id, vin)
)wƒItableModelsModelsCREATE TABLE Models(
model_id INTEGER PRIMARY KEY AUTOINCREMENT,
model_name VARCHAR(50) NOT NULL,
model_base_price INTEGER NOT NULL,
brand_id INTEGER NOT NULL,
FOREIGN KEY (brand_id) REFERENCES Brands(brand_id)
)o…+tableCar_VinsCar_VinsCREATE TABLE Car_Vins(
vin INTEGER PRIMARY KEY AUTOINCREMENT,
option_set_id INTEGER NOT NULL,
manufactured_date DATE NOT NULL,
manufactured_plant_id INTEGER NOT NULL,
FOREIGN KEY (manufactured_plant_id) REFERENCES Manufacture_Plant(manufactured_plant_id),
FOREIGN KEY (option_set_id) REFERENCES Car_Options(option_set_id)
)P++Ytablesqlite_sequencesqlite_sequenceCREATE TABLE sqlite_sequence(name,seq)XtableCustomersCustomersCREATE TABLE Customers(
customer_id INTEGER PRIMARY KEY AUTOINCREMENT,
first_name VARCHAR(50) NOT NULL,
last_name VARCHAR(50) NOT NULL,
gender STRING CHECK(gender = "Male" or gender = "Female"),
household_income INTEGER,
birthdate DATE NOT NULL,
phone_number INTEGER NOT NULL,
email VARCHAR(128)
)
'ð¡
y %±ðƒƒ>†OtableCar_VinsCar_VinsCREATE TABLE Car_Vins(
vin INTEGER PRIMARY KEY AUTOINCREMENT,
model_id INTEGER NOT NULL,
option_set_id INTEGER NOT NULL,
manufactured_date DATE NOT NULL,
manufactured_plant_id INTEGER NOT NULL,
FOREIGN KEY (model_id) REFERENCES Models(model_id),
FOREIGN KEY (manufactured_plant_id) REFERENCES Manufacture_Plant(manufacture_plant_id),
FOREIGN KEY (option_set_id) REFERENCES Car_Options(option_set_id)
)„q##‰)tableCar_OptionsCar_OptionsCREATE TABLE Car_Options(
option_set_id INTEGER PRIMARY KEY AUTOINCREMENT,
model_id INTEGER NULL,
engine_id INTEGER NOT NULL,
transmission_id INTEGER NOT NULL,
chassis_id INTEGER NOT NULL,
premium_sound_id INTEGER,
color VARCHAR(30) NOT NULL,
option_set_price INTEGER NOT NUll,
FOREIGN KEY (model_id) REFERENCES Models(model_id),
FOREIGN KEY (engine_id) REFERENCES Car_Parts(part_id),
FOREIGN KEY (premium_sound_id) REFERENCES Car_Parts(part_id),
FOREIGN KEY (transmission_id) REFERENCES Car_Parts(part_id),
FOREIGN KEY (chassis_id) REFERENCES Car_Parts(part_id)