Answered step by step
Verified Expert Solution
Question
1 Approved Answer
- - Name: Amon Ahoure - - Assignment: M 0 2 Hands - On Lab - Constructing the Database - - Date: 1 / 2
Name: Amon Ahoure
Assignment: M HandsOn Lab Constructing the Database
Date:
CREATE TABLE CUSTOMERS
CUSTOMERID NUMBER NOT NULL,
FIRSTNAME VARCHAR NOT NULL,
LASTNAME VARCHAR NOT NULL,
STREETADDRESS VARCHAR NOT NULL,
CITY VARCHAR NOT NULL,
ZIPCODE VARCHAR NOT NULL,
COUNTRY CHAR NOT NULL,
PHONENUMBER VARCHAR NOT NULL,
EMAIL VARCHAR NOT NULL,
DATEOFBIRTH DATE,
GENDER VARCHAR
;
CREATE TABLE BOOKS
BOOKID NUMBER NOT NULL,
BOOKTITLE VARCHAR NOT NULL,
BOOKDESCRIPTION VARCHAR NOT NULL,
BOOKCATEGORYCD CHAR NOT NULL,
BOOKPRICE NUMBER NOT NULL,
BOOKREVIEWS NUMBER NOT NULL,
USERRATING NUMBER NOT NULL
;
CREATE TABLE BOOKCATEGORY
BOOKCATEGORYCD CHAR NOT NULL,
BOOKCATEGORYNAME VARCHAR NOT NULL,
BOOKCATEGORYDESCRIPTION VARCHAR NOT NULL
;
CREATE TABLE ORDERS
ORDERNBR NUMBER NOT NULL,
CUSTOMERID NUMBER NOT NULL,
ORDERDATE TIMESTAMP NOT NULL,
ORDERTOTAL NUMBER NOT NULL,
SALESPERSON NUMBER NOT NULL
;
CREATE TABLE ORDERITEMS
ORDERITEMID NUMBER NOT NULL,
ORDERNBR NUMBER NOT NULL,
BOOKID NUMBER NOT NULL,
UNITPRICE NUMBER NOT NULL,
QUANTITY NUMBER NOT NULL
;
ALTER TABLE CUSTOMERS ADD CONSTRAINT PKCUSTOMERS PRIMARY KEY CUSTOMERID;
ALTER TABLE BOOKS ADD CONSTRAINT PKBOOKS PRIMARY KEY BOOKID;
ALTER TABLE BOOKCATEGORY ADD CONSTRAINT PKBOOKCATEGORY PRIMARY KEY BOOKCATEGORYCD;
ALTER TABLE ORDERS ADD CONSTRAINT PKORDERS PRIMARY KEY ORDERNBR;
ALTER TABLE ORDERITEMS ADD CONSTRAINT PKORDERITEMS PRIMARY KEY ORDERITEMID;
Adding foreign key constraint to the tables
ALTER TABLE BOOKS ADD CONSTRAINT FKBOOKBOOKCAT FOREIGN KEY BOOKCATEGORYCD
REFERENCES BOOKCATEGORY BOOKCATEGORYCD;
ALTER TABLE ORDERS ADD CONSTRAINT FKORDCUST FOREIGN KEY CUSTOMERID
REFERENCES CUSTOMERS CUSTOMERID;
ALTER TABLE ORDERS ADD CONSTRAINT FKORDEMP FOREIGN KEY SALESPERSON
REFERENCES EMPLOYEES EMPLOYEEID;
ALTER TABLE ORDERITEMS ADD CONSTRAINT FKORDITMORD FOREIGN KEY ORDERNBR
REFERENCES ORDERS ORDERNBR;
ALTER TABLE ORDERITEMS ADD CONSTRAINT FKORDITMPROD FOREIGN KEY BOOKID
REFERENCES BOOKS BOOKID;
ALTER TABLE ORDERS ADD CONSTRAINT FKORDEMP FOREIGN KEY SALESPERSONID
REFERENCES EMPLOYEE EMPLOYEEID;
ALTER TABLE ORDERITEMS ADD CONSTRAINT UKORDITM UNIQUE ORDERNBR BOOKID;
CREATE TABLE ORDERITEMS
ORDERITEMID NUMBER NOT NULL,
ORDERNBR NUMBER NOT NULL,
BOOKID NUMBER NOT NULL,
UNITPRICE NUMBER NOT NULL,
QUANTITY NUMBER NOT NULL,
CONSTRAINT PKORDERITEMS PRIMARY KEY ORDERITEMID
CONSTRAINT FKORDITMORD FOREIGN KEY ORDERNBR REFERENCES ORDERS ORDERNBR
CONSTRAINT FKORDITMPROD FOREIGN KEY BOOKID REFERENCES BOOKS BOOKID
CONSTRAINT UKORDITM UNIQUE ORDERNBR BOOKID
;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started