Question: create Entity relationship of the database below postgresql draw it fully showing all connections and key the lecturer provided a model answer so please refer
create Entity relationship of the database below postgresql draw it fully showing all connections and key the lecturer provided a model answer so please refer to it in the photoDiagram of Database Models Implemented but with using my database example below Create staff table insure all staff usernames are unique
CREATE TABLE staff
staffid SERIAL PRIMARY KEY,
staffname VARCHAR UNIQUE NOT NULL,
staffpin INT NOT NULL,
stafftype INT NOT NULL
;
Create customer table
CREATE TABLE customer
customerid SERIAL PRIMARY KEY,
customername VARCHAR NOT NULL,
customerallergies TEXT
;
Create menu table
CREATE TABLE menu
dishid SERIAL PRIMARY KEY,
dishname VARCHAR NOT NULL,
dishcalories INT NOT NULL,
dishprice DECIMAL NOT NULL,
dishdescription VARCHAR
;
CREATE TABLE allergens
allergenid SERIAL PRIMARY KEY,
allergenname VARCHAR
;
GRANT ALL ON allergens TO root;
INSERT INTO allergens allergenname VALUES Gluten;
INSERT INTO allergens allergenname VALUES Dairy;
INSERT INTO allergens allergenname VALUES Nuts;
create table relation for menu items and allergens
CREATE TABLE dishallergens
dishid INT,
allergenid INT,
FOREIGN KEY dishid REFERENCES menudishid ON DELETE CASCADE,
FOREIGN KEY allergenid REFERENCES allergensallergenid ON DELETE CASCADE
;
GRANT ALL ON orders TO root;
CREATE TABLE orderdetails
orderdetailid SERIAL PRIMARY KEY,
orderid INT REFERENCES ordersorderid ON DELETE CASCADE,
dishid INT REFERENCES menudishid ON DELETE CASCADE,
quantity INT
;
GRANT ALL ON orderdetails TO root;
Create needshelp table
CREATE TABLE needshelp
helpid SERIAL PRIMARY KEY,
customerid SERIAL REFERENCES customercustomerid ON DELETE CASCADE,
resolved BOOLEAN DEFAULT FALSE
;
GRANT ALL ON needshelp TO root;
CREATE TABLE tables
tablenumber SERIAL PRIMARY KEY,
customerid INT REFERENCES customercustomerid ON DELETE CASCADE,
staffid INT REFERENCES staffstaffid ON DELETE CASCADE
;
GRANT ALL ON tables TO root;
CREATE TABLE payments
paymentid SERIAL PRIMARY KEY,
paymenttime TIMESTAMP NOT NULL,
paymentamount NUMERIC NOT NULL,
tablenumber SERIAL REFERENCES tablestablenumber ON DELETE CASCADE,
cardholder VARCHAR
cardending INT,
cardexpiry VARCHAR
;
GRANT ALL ON payments TO root; note that this questions was not answered before so please focus as the answer provided was incomplete. thank u
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
