Hi rpeare. Thank you.
The structure is the same as the one which you have listed. However we are not allowed to use dataless keys for this assignment so I struggle with having tblOrder and tblOrderDetails as they both have compound primary keys and I dont know how to keep referential integrity with compound keys. I may have misunderstood how to create the tables but here is what i did. I have the following tables:
CUSTOMER
PK (Customer Email) and other related fields
SERVICE
PK ( Service-Name) and other related fields
STAFF
PK (Staff Email) and other related fields
REQUEST
Code:
CREATE TABLE REQUEST([Customer-Email] VARCHAR(15) NOT NULL,[Service-Name] VARCHAR(30) NOT NULL,[staff-Email] VARCHAR(15) NOT NULL,[Request-Date/time] DATE/TIME NOT NULL,[Authorised-by] VARCHAR(15) NOT NULL,[Served-Date/Time] DATE NOT NULL,[Request-Date/time] DATE NOT NULL,[Discount] decimal(3,2) ,[Served-Price] DECIMAL(10, 2), [Served-Location] VARCHAR(15) NOT NULL,[Total-Price] DECIMAL(10, 2), CONSTRAINT REQPK PRIMARY KEY([Customer-Email],[Service-Name],[Request-Date/time],[Served-Date/Time]),CONSTRAINT REQSE FOREIGN KEY([staff-Email]) REFERENCES STAFF([staffEmail]) ON DELETE SET NULL ON UPDATE CASCADE,CONSTRAINT REQCE FOREIGN KEY([Customer-Email]) REFERENCES CUSTOMER([CustomerEmail]) ON DELETE CASCADE ON UPDATE CASCADE,CONSTRAINT REQSCE3 FOREIGN KEY([Service-Name]) REFERENCES SERVICE([Service-Name]) ON DELETE SET NULL ON UPDATE CASCADE);
So REQUEST has the compound Primary key: [Customer-Email],[Service-Name],[Request-Date/time],[Served-Date/Time]
If I was to split it into 2 tables like you did (REQUEST AND SERVICE) I would :
REQUEST:
PK ([Customer-Email],[Request-Date/time])
and
SERVICE:
PK ([Customer-Email],[Service-Name],[Request-Date/time],[Served-Date/Time])
SERVICE would need to have the primary key of REQUEST as a Foreign key to ensure there are no service records that do not have requests. I dont know who to code this using the Primary keys as I have created them.
Does this make sense? Any ideas?
Many thanks once again.
Tony