Question

In: Computer Science

• Relational Schema Create a relational database schema consisting of the four relation schemas representing various...

  • • Relational Schema

Create a relational database schema consisting of the four relation schemas representing various entities recorded by a furniture company.  

Write CREATE TABLE statements for the following four relation schemas. Define all necessary attributes, domains, and primary and foreign keys.

Customer(CustomerID, Name, Address)

FullOrder(OrderID, OrderDate, CustomerID)

Request(OrderID, ProductID, Quantity)

Product(ProductID, Description, Finish, Price)

You should assume the following: Each CustomerID is a number with at most three digits, each OrderID is a number with at most five digits, and each ProductID is a number with at most two digits. Each Name is at most 25 characters long, and each Address is at most 50 characters long. Each Description is at most 28 characters long, and each Finish is at most 10 characters long. Quantity and Price are integer and float respectively.

In this schema, primary and foreign keys are not marked. Identify primary and foreign keys and other custom constraints. Declare PK and FK in your CREATE TABLE statement and custom constraints as follows:

  • Each Price is a non-negative value (zero is allowed) representing a price in dollars and cents that cannot exceed 999.99.
  • Each Quantity is a positive whole number between 1 and 100, inclusive.

Populate the database as follows:

CUSTOMER:

CUSTOMERID NAME ADDRESS

---------------------- ------------------------------ --------------------

2 CASUAL FURNITURE PLANO, TX

6 MOUNTAIN GALLERY BOULDER, CO

FULLORDER:

ORDERID ORDERDATE CUSTOMERID

---------------------- ------------------------- ----------------------

1006 24-MAR-10 2

1007 25-MAR-10 6

1008 25-MAR-10 6

1009 26-MAR-10 2

PRODUCT:

PRODUCTID DESCRIPTION FINISH PRICE

---------------------- ------------------------------ ---------- ----------

10 WRITING DESK OAK 425

30 DINING TABLE ASH 600

40 ENTERTAINMENT CENTER MAPLE 650

70 CHILDRENS DRESSER PINE 300

REQUEST:

ORDERID PRODUCTID QUANTITY

---------------------- ---------------------- ----------------------

1006 10 4

1006 30 2

1006 40 1

1007 40 3

1007 70 2

1008 70 1

1009 10 2

1009 40 1                  

Remember to insert the records containing primary key values before inserting the records containing the foreign keys that reference those values (or your insert statements will fail).

Display the contents of each table by adding four statements of the form SELECT * FROM TABLE_NAME ; to the end of your script, where TABLE_NAME is substituted by the four table names above.

In order to avoid conflicts, include DROP TABLE commands for all four tables before your CREATE TABLE statements. Either drop tables containing foreign keys before the tables containing the referenced primary keys, or use CASCADE CONSTRAINTS. Verify that the tables have been defined correctly before going on to the next step.

Run the complete script. Be sure that that the contents of the four tables are displayed correctly by your script.

Submit a Q1.sql file.

Note:

You must code this schema using ‘Create Table’ statements . You should not use any other tool except Oracle SQLDeveloper. No points will be given for auto-generated schemas using other 3rd party tools or web-based editors.

Solutions

Expert Solution

/* Drop tables if exist */

DROP TABLE Customer;

DROP TABLE FullOrder;

DROP TABLE Request;

DROP TABLE Product;

/* Create required four tables */

CREATE TABLE Customer

(

CustomerID int CHECK(CustomerID BETWEEN 1 AND 999) NOT NULL PRIMARY KEY ,

Name varchar(25),

Address varchar(50)

);

CREATE TABLE FullOrder

(

OrderID int CHECK(OrderID BETWEEN 1 AND 99999) NOT NULL PRIMARY KEY ,

OrderDate date,

CustomerID int FOREIGN KEY REFERENCES Customer(CustomerID)

);

CREATE TABLE Request

(

OrderID int FOREIGN KEY REFERENCES FullOrder(OrderID) ,

ProductID int FOREIGN KEY REFERENCES Product(ProductID) ,

Quantity int CHECK(Quantity BETWEEN 1 AND 100)

);

CREATE TABLE Product

(

ProductID int CHECK(ProductID BETWEEN 1 AND 99) NOT NULL PRIMARY KEY,

Description varchar(28),

Finish varchar(10),

Price float CHECK(Price >=0 AND Price <= 999.99 )

);

/* Inserting data to the four tables */

INSERT INTO Customer

(

VALUES( 2, 'CASUAL' , ' FURNITURE PLANO, TX' ),

VALUES( 6, 'MOUNTAIN' , ' GALLERY BOULDER, CO' )

);

INSERT INTO FullOrder

(

VALUES( 1006, 24-MAR-10, 2 ),

VALUES( 1007, 25-MAR-10, 6 ),

VALUES( 1008, 25-MAR-10, 6 ),

VALUES( 1009, 26-MAR-10, 2 )

);

INSERT INTO Product

(

VALUES( 10 'WRITING DESK OAK', 425 ),

VALUES( 30, 'DINING TABLE ASH', 600 ),

VALUES( 40, 'ENTERTAINMENT CENTER MAPLE', 650 ),

VALUES( 70, 'CHILDRENS DRESSER PINE', 300 )

);

INSERT INTO Request

(

VALUES( 1006, 10, 4 ),

VALUES( 1006, 30, 2 ),

VALUES( 1006, 40, 1 ),

VALUES( 1007, 40, 3 ),

VALUES( 1007, 70, 2 ),

VALUES( 1008, 70, 1 ),

VALUES( 1009, 10, 2 ),

VALUES( 1009, 40, 1 )

);

/* Showing data present the four tables */

SELECT * FROM Customer;

SELECT * FROM FullOrder;

SELECT * FROM Product;

SELECT * FROM Request;


Related Solutions

Database: Question 11 Using the ERD from problem 10, create the relational schema.(Create an appropriate collection...
Database: Question 11 Using the ERD from problem 10, create the relational schema.(Create an appropriate collection of attributes for each of the entities. Make sure you use the appropriate naming conventions to name the attributes.)
Consider the schemas of the following relational database for a company. The company has different departments...
Consider the schemas of the following relational database for a company. The company has different departments at different cities in different states: employee(employee-id, dept-id, name, street-num, street-name, city, state, zip, salary) department(dept-id, dept-name, city, state) manager(manager-id, employee-id) NOTES: manager-id in the manager relation is a foreign key to the employee relation. employee-id in the manager relation is a foreign key to the employee relation. dept-id in the employee relation is a foreign key to the department relation. An employee belongs...
What is a relation? What is a relational DB or database? What is an unnormalized relation?...
What is a relation? What is a relational DB or database? What is an unnormalized relation? Is it a relation according to the definition of the word relation? What is a primary key? What is the primary key for each table in the Colonial Adventure Tours database shown in Figures 1-15, 1-16, 1-17, 1-18, and 1-19 in Chapter 1?
tableA is a table in a relational database with a composite prime key consisting of fields...
tableA is a table in a relational database with a composite prime key consisting of fields F1 and F2. You have determined that tableA is 1NF. There are four other fields in tableA. Two of them, F10 and F12, are functionally determined by F1. The other two, F50 and F55, are functionally determined by F2. Because all fields are functionally determined by at least a portion of the key, is tableA 2NF?   If you believe the table is not yet...
Define the four main types of relational constraints and use the example relational database (Figure 1)...
Define the four main types of relational constraints and use the example relational database (Figure 1) to illustrate each of these constraints. Figure 1 House(MLS, Addr, NumRooms, NumBedRooms, SellID, OfficeID, Price) Seller(SellID, Name) PotentialBuyer(BuyID, Name) REOffice(OffID, Name, Addr, Phone) Agent(AgID, OffID, Name) Showing(AgID, MLS, BuyID, Date)
Using MYSQL in terminal, create the tables for your above designed relational schema and populate your...
Using MYSQL in terminal, create the tables for your above designed relational schema and populate your tables with appropriate data. All except time slot and the relationship it participates in. Use the names for the tables and attributes from the ER schema. Use ON DELETE CASCADE for foreign keys. Each basic table (corresponding to an entity in the ER schema developed for Part 1) should have 5-10 rows. Campus can have just 2. Building should have at least 6. At...
Listed below is the relational database schema for an online store(SQL/Java): MEMBER(last_name, first_name, email, password, user,street,...
Listed below is the relational database schema for an online store(SQL/Java): MEMBER(last_name, first_name, email, password, user,street, city, state, zip, card_type, card_no, expiration, name_on_card) book_SALE(listing_no, seller, isbn, condition, price) ORDERS(order_no, buyer, order_date, tot) ITEM(order_no, listing_no) BOOK(isbn, title, author, edition, publisher, keywords) The bold attribute(s) in a relation is the primary key of that relation. The italized attributes in some relations denote foreign keys. The seller attribute in the book_SALE relation is a foreign key to the user attribute in the MEMBER...
Listed below is the relational database schema for an online store(SQL/Java): MEMBER(last_name, first_name, email, password, user,street,...
Listed below is the relational database schema for an online store(SQL/Java): MEMBER(last_name, first_name, email, password, user,street, city, state, zip, card_type, card_no, expiration, name_on_card) book_SALE(listing_no, seller, isbn, condition, price) ORDERS(order_no, buyer, order_date, tot) ITEMS(order_no, listing_no) BOOK(isbn, title, author, edition, publisher, keywords) The bold attribute(s) in a relation is the primary key of that relation. The italized attributes in some relations denote foreign keys. Create/Define the table.
Database - SQL - Operations CS 203 Discrete Structure 2 Create a Microsoft Access Database consisting...
Database - SQL - Operations CS 203 Discrete Structure 2 Create a Microsoft Access Database consisting of the following two tables: Part_needs and Parts_Inventory Part_needs Supplier Part_number Project 23 1092 1 23 1101 3 23 9048 4 31 4975 3 31 3477 2 32 6984 4 32 9191 2 33 1001 1 Parts_Inventory Part_number Project Quantity Color_code 1001 1 14 8 1092 1 2 2 1101 3 1 1 3477 2 25 2 4975 3 6 2 6984 4 10...
"Create a program that displays a table consisting of four rows and five columns. The first...
"Create a program that displays a table consisting of four rows and five columns. The first column should display the numbers 1 through 4. The second and sub-sequent columns should display the result of multiplying the number in the first column by the numbers 2 through 5. If necessary, create a new project named Introductory14 Project, and save it in the Cpp8\Chap08 folder. Enter the C++ instructions into a source file named Introductory14.cpp. Also enter appropriate comments and any additional...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT