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...
A database schema consisting of three relations STUDENT, COURSE, and STAFF is created as follows: CREATE...
A database schema consisting of three relations STUDENT, COURSE, and STAFF is created as follows: CREATE TABLE STUDENT (STU_ID CHAR(4), STUDENT_NAME CHAR(20), ADDRESS CHAR(20), BIRTHDATE DATE, GENDER CHAR(6)); CREATE TABLE COURSE (COURSE_ID CHAR(6), COURSE_TITLE CHAR(20), STAFF_ID CHAR(3), SECTION NUMBER(2)); CREATE TABLE STAFF (STAFF_ID CHAR(3), STAFF_NAME CHAR(20), GENDER CHAR(6), DEPARTMENT CHAR(20), BOSS_ID CHAR(3) SALARY NUMBER(8,2)); Write down SQL statement for each query below: 1) Find out the information of staff members who are female and earn either below $5,000 or above...
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...
Question 2: consider the following library relational database schema Write a program segment to retrieves the...
Question 2: consider the following library relational database schema Write a program segment to retrieves the list of books that became overdue yesterday and that prints the book title and borrower name for each. 1- Use JDBC with Java as the host language
Database - Relational Theory The state of a table or relation relates to its current content....
Database - Relational Theory The state of a table or relation relates to its current content. Consider the formal terminology of the relational model. 1) Which descriptive term of a relation applies to the state of a relation? 2) Which descriptive term of a relation is not affected a change in the state of the relation? 3) In addition to identifying these terms, provide a brief definition of each of term.
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)
Consider the following universal relation THE following database schema is in 4NF. What can you infer...
Consider the following universal relation THE following database schema is in 4NF. What can you infer about multi-valued dependencies? A C D A B C E E F A-It does not have multi-valued dependencies. B-The multi-valued dependency A ->-> C does not hold. If the multi-valued dependency A ->-> C held, the database would not be in 4NF. C-The multi-valued dependency A ->-> B does not hold. If the multi-valued dependency A ->-> B held, the database would not be...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT