Final answer:
The answer provides an SQL script to create a database for a fictional online clothes store in accordance with the provided relational model, including table creation with primary and foreign key constraints.
Step-by-step explanation:
To create a database for an online clothes store called ClothesInc, we will follow the relational model provided and write the appropriate SQL script to set up the database schema:
SQL Script for Creating Database
ClothesInc Database Setup:
- Create Tables with Primary Keys
CREATE TABLE Store (
storeId TEXT PRIMARY KEY,
sName TEXT NOT NULL,
sAddress TEXT,
sPostCode TEXT
);
CREATE TABLE StoreEmployee (
employeeId TEXT PRIMARY KEY,
eName TEXT,
eAddress TEXT,
ePostCode TEXT,
eEmail TEXT,
mobPh TEXT,
storeId TEXT,
FOREIGN KEY (storeId) REFERENCES Store (storeId)
);
CREATE TABLE Customer (
customerId TEXT PRIMARY KEY,
cName TEXT,
cMobilePh TEXT,
cEmail TEXT,
cStartDate TEXT
);
CREATE TABLE Order (
orderId TEXT PRIMARY KEY,
oDate TEXT,
total INTEGER,
GST INTEGER,
deliveryAddress TEXT,
orderStatus TEXT,
customerId TEXT,
FOREIGN KEY (customerId) REFERENCES Customer (customerId)
);
CREATE TABLE OrderDetail (
orderId TEXT,
productId TEXT,
quantity INTEGER,
retailPrice INTEGER,
PRIMARY KEY (orderId, productId),
FOREIGN KEY (orderId) REFERENCES Order (orderId),
FOREIGN KEY (productId) REFERENCES Product (productId)
);
CREATE TABLE Payment (
paymentId TEXT PRIMARY KEY,
type TEXT,
amount INTEGER,
pDate TEXT,
bankTransactNo TEXT,
orderId TEXT,
FOREIGN KEY (orderId) REFERENCES Order (orderId)
);
CREATE TABLE Product (
productId TEXT PRIMARY KEY,
size TEXT,
colour TEXT,
style TEXT,
quantityOnHand INTEGER,
reorderQty INTEGER,
retailPrice INTEGER,
supplierId TEXT,
FOREIGN KEY (supplierId) REFERENCES Supplier (supplierId)
);
CREATE TABLE Supplier (
supplierId TEXT PRIMARY KEY,
supplierName TEXT
);
CREATE TABLE ProductSupplier (
productId TEXT,
supplierId TEXT,
PRIMARY KEY (productId, supplierId),
FOREIGN KEY (productId) REFERENCES Product (productId),
FOREIGN KEY (supplierId) REFERENCES Supplier (supplierId)
);
- Create Relationships Between Tables Using Foreign Keys
As shown in the SQL code above, the foreign key relationships between tables have been established using the FOREIGN KEY clause within the table creation statements for each table that has foreign key dependencies.
Ensure that the data types and constraints are in accordance with the provided relational model, particularly that primary keys and foreign keys are strings and that certain integer types are used as specified.