Knowee
Questions
Features
Study Tools

i. Create a database called orderproc_db for an Order processing company usingMySQL.ii. Replace the data types in the tables given below with MySQL Compatible format.iii. Using the orderproc_db database, create the following tables.CUSTOMER (custno: INT, cname: STRING, city: STRING)ORDE (orderno: INT, odate: DATE, custno: INT, ord_amt: INT)ITEM (itemno: INT, unit_price: INT)ORDE_ITEM (orderno: INT, itemno: INT, qty: INT)WAREHOUSE (warehouseno: INT, city: STRING)SHIPMENT (orderno: INT, warehouseno: INT, ship_date: DATE)iv. Identify the primary key and define primary key constrains for the table.v. Identify the foreign keys and enforce referential integrity for the tables.vi. Describe the structures of the tables you have created above.vii. Insert the records to the tables. Records are available as text files with the respectivetable names in a folder called “Tables” on your desktop. You need to properly formatthese records before inserting into the tables.viii. List all customers from Batticaloa.ix. Propose an alternative method to execute the above question (viii).x. Select all customers who are from Batticaloa or Jaffna.xi. How many customers are there in Colombo?xii. List the customer’s name ending with the letters “na”.xiii. List all the order amount above 50000.xiv. List all customers name who made order above 50000.xv. List all customers name who have at least one warehouse in their city.xvi. How many different cities are there in the customer table.xvii. How many warehouses are there in Colombo?.xviii. How do you check all order dates are less than or equal to shipping dates?xix. List all the order number, order date, customer number and order amount where all theshipment made from Colombo warehouses.

Question

i. Create a database called orderproc_db for an Order processing company usingMySQL.ii. Replace the data types in the tables given below with MySQL Compatible format.iii. Using the orderproc_db database, create the following tables.CUSTOMER (custno: INT, cname: STRING, city: STRING)ORDE (orderno: INT, odate: DATE, custno: INT, ord_amt: INT)ITEM (itemno: INT, unit_price: INT)ORDE_ITEM (orderno: INT, itemno: INT, qty: INT)WAREHOUSE (warehouseno: INT, city: STRING)SHIPMENT (orderno: INT, warehouseno: INT, ship_date: DATE)iv. Identify the primary key and define primary key constrains for the table.v. Identify the foreign keys and enforce referential integrity for the tables.vi. Describe the structures of the tables you have created above.vii. Insert the records to the tables. Records are available as text files with the respectivetable names in a folder called “Tables” on your desktop. You need to properly formatthese records before inserting into the tables.viii. List all customers from Batticaloa.ix. Propose an alternative method to execute the above question (viii).x. Select all customers who are from Batticaloa or Jaffna.xi. How many customers are there in Colombo?xii. List the customer’s name ending with the letters “na”.xiii. List all the order amount above 50000.xiv. List all customers name who made order above 50000.xv. List all customers name who have at least one warehouse in their city.xvi. How many different cities are there in the customer table.xvii. How many warehouses are there in Colombo?.xviii. How do you check all order dates are less than or equal to shipping dates?xix. List all the order number, order date, customer number and order amount where all theshipment made from Colombo warehouses.

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

This is a complex question that involves multiple steps. Here's how you can do it:

i. Creating a database:

CREATE DATABASE orderproc_db;
USE orderproc_db;

ii. Replacing data types: In MySQL, the STRING data type is replaced with VARCHAR or CHAR. Let's use VARCHAR(255) for this example.

iii. Creating tables:

CREATE TABLE CUSTOMER (
    custno INT,
    cname VARCHAR(255),
    city VARCHAR(255),
    PRIMARY KEY (custno)
);

CREATE TABLE ORDE (
    orderno INT,
    odate DATE,
    custno INT,
    ord_amt INT,
    PRIMARY KEY (orderno),
    FOREIGN KEY (custno) REFERENCES CUSTOMER(custno)
);

CREATE TABLE ITEM (
    itemno INT,
    unit_price INT,
    PRIMARY KEY (itemno)
);

CREATE TABLE ORDE_ITEM (
    orderno INT,
    itemno INT,
    qty INT,
    PRIMARY KEY (orderno, itemno),
    FOREIGN KEY (orderno) REFERENCES ORDE(orderno),
    FOREIGN KEY (itemno) REFERENCES ITEM(itemno)
);

CREATE TABLE WAREHOUSE (
    warehouseno INT,
    city VARCHAR(255),
    PRIMARY KEY (warehouseno)
);

CREATE TABLE SHIPMENT (
    orderno INT,
    warehouseno INT,
    ship_date DATE,
    PRIMARY KEY (orderno, warehouseno),
    FOREIGN KEY (orderno) REFERENCES ORDE(orderno),
    FOREIGN KEY (warehouseno) REFERENCES WAREHOUSE(warehouseno)
);

iv. Primary keys are defined in the CREATE TABLE statements above.

v. Foreign keys are also defined in the CREATE TABLE statements above.

vi. To describe the structure of the tables, use the DESCRIBE statement:

DESCRIBE CUSTOMER;
DESCRIBE ORDE;
DESCRIBE ITEM;
DESCRIBE ORDE_ITEM;
DESCRIBE WAREHOUSE;
DESCRIBE SHIPMENT;

vii. To insert records, you would use the INSERT INTO statement. However, without seeing the format of the text files, it's hard to provide a specific example.

viii. To list all customers from Batticaloa:

SELECT * FROM CUSTOMER WHERE city = 'Batticaloa';

ix. An alternative method could be to use a LIKE statement:

SELECT * FROM CUSTOMER WHERE city LIKE 'Batticaloa';

x. To select all customers from Batticaloa or Jaffna:

SELECT * FROM CUSTOMER WHERE city IN ('Batticaloa', 'Jaffna');

xi. To count customers in Colombo:

SELECT COUNT(*) FROM CUSTOMER WHERE city = 'Colombo';

xii. To list customers ending with "na":

SELECT * FROM CUSTOMER WHERE cname LIKE '%na';

xiii. To list order amounts above 50000:

SELECT * FROM ORDE WHERE ord_amt > 50000;

xiv. To list customers who made orders above 50000:

SELECT cname FROM CUSTOMER WHERE custno IN (SELECT custno FROM ORDE WHERE ord_amt > 50000);

xv. To list customers who have a warehouse in their city:

SELECT cname FROM CUSTOMER WHERE city IN (SELECT city FROM WAREHOUSE);

xvi. To count different cities in the customer table:

SELECT COUNT(DISTINCT city) FROM CUSTOMER;

xvii. To count warehouses in Colombo:

SELECT COUNT(*) FROM WAREHOUSE WHERE city = 'Colombo';

xviii. To check if all order dates are less than or equal to shipping dates:

SELECT * FROM ORDE o JOIN SHIPMENT s ON o.orderno = s.orderno WHERE o.odate > s.ship_date;

If this query returns any rows, then there are some orders where the order date is greater than the shipping date.

xix. To list order number, order date, customer number and order amount where all the shipment made from Colombo warehouses:

SELECT o.orderno, o.odate, o.custno, o.ord_amt FROM ORDE o JOIN SHIPMENT s ON o.orderno = s.orderno JOIN WAREHOUSE w ON s.warehouseno = w.warehouseno WHERE w.city = 'Colombo';

Please note that these queries assume that the data in your tables is consistent and follows the structure you provided. If there are any inconsistencies, some queries may not work as expected.

This problem has been solved

Similar Questions

Create a table named orders with columns "order_id" (int), "customer_id" (int), "order_date" (date), "total_amount" (decimal), and "status" (varchar). The table should be configured with constraints such that "order_id" and "customer_id" cannot be empty, and "order_id" serves as the primary key.

onsider the following relations to answer Question.Manufacturer (ManufacturerId, MName, DateOfBirth, Gender MAddress, AwardWon)Part (PartNo, PName, Description, ManufacturerId)Order (PartNo, OrderNo, OrderQuantity, OrderedDate, CustomerId)Customer (CustomerId, Email, CName, CAddress, Job, TotalNoOfCustomers)Most suitable data type (s) for OrderNo, OrderQuantity, OrderedDate in Order relation respectively is/are:Select one:a.Number, Number, Dateb.Text, Text, Datec.Number, Number, Numberd.Number, Text, Datee.Text, Text, Text

Using the following schema, write SQL statement to fetch the correct data.Insurance_Company (c_id, c_name, city, state, policy_no, policy_name, premium, cust_id, a_id)Agent (a_id, a_name, address, a_city, a_state, c_name, salary, incentive)Customer (cust_id, name, age, cust_address, cust_city, cust_state, a_id, policy_no)Create tables with Primary Key, foreign key constraints in given schemas.1) Display the details of customer who have taken policy from ‘Ahmedabad Insurance Company’.2) Display agent name who have not sold even a single policy.3) Display the name of Insurance company who has maximum number of customers

Query the customer_number from the orders table for the customer who has placed the largest number of orders.It is guaranteed that exactly one customer will have placed more orders than any other customer.The orders table is defined as follows:ColumnTypeorder_number (PK)intcustomer_numberintorder_datedaterequired_datedateshipped_datedatestatuschar(15)commentchar(200)Sample Inputorder_numbercustomer_numberorder_daterequired_dateshipped_date112017-04-092017-04-132017-04-12222017-04-152017-04-202017-04-18332017-04-162017-04-252017-04-20442017-04-182017-04-282017-04-25Sample Outputcustomer_number3ExplanationThe customer with number '3' has two orders, which is greater than either customer '1' or '2' because each of them only has one order.So the result is customer_number '3'. Follow up: What if more than one customer have the largest number of orders, can you find all the customer_number in this case?Optionsselect customer_numberfrom ( select customer_number, count(*) as cnt from orders group by customer_number) as eorder by e.cnt desclimit 1;select customer_number select customer_number, count(*) as cnt from orders group by customer_number) as eorder by e.cnt desclimit 1;select customer_numberfrom ( select customer_number, count(*) as cnt from orders group by customer_number) as elimit 1;select customer_numberfrom ( select customer_number, count(*) as cnt group by customer_number) as eorder by e.cnt desclimit 1;

Orders table got below attributesOrder_no, Custnbr, Product, Qty, Amt, DiscountCustomers table got below attributesCustnbr, Company, Custrep, CreditlimPrint the Order_no, Amt, Company and creditlim of the customers who placed orders. Select Order_no, Amt, Company, Creditlim from Customers outer join Orders on customers.custnbr=orders.custnbrSelect Order_no, Amt, Company, Creditlim from Customers left outer join Orders on customers.custnbr = orders.custnbrSelect Order_no, Amt, Company, Creditlim from Customers inner join Orders on customers.custnbr = orders.custnbrSelect Order_no, Amt, Company, Creditlim from Customers right outer join Orders on customers.custnbr = orders.custnbr

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.