Question

In: Computer Science

Use MYSQL to create the set of database tables of the relational database model and complete...

Use MYSQL to create the set of database tables of the relational database model and complete the associated queries given.

Procedure: 1) Write all the SQL statements, necessary to create all tables and relationships, with Primary & Foreign keys.

2) Execute each statement in the correct order to create the relational database in MYSQL.

3)Insert some data into each table.

4) Use all your SQL create and Insert statements (from MS Word) to execute in the MYSQL WorkBench

5) Write in MS Word and execute in MYSQL WorkBench the statements necessary to; i. display all tables, ii. identify sales total for each item iii. identify delivery confirmation of sold items iv. identify marketing level for sold items

(Tables that have to be created)

  • Sales details

  • Marketing details

  • Customer details

  • Production details

  • Delivery details

  • Management details

Solutions

Expert Solution

/* CREATE DATABASE */

CREATE DATABASE SampleProduction

/* CREATE TABLE : ProductionDetails */

CREATE TABLE ProductionDetails (

ProductID int auto_increment not null primary key,

ProductName varchar(255),

Manufacturer Varchar(255),

ManufacturingDate DateTime,

ExpiryDate DateTime,

UnitPrice Money,

Quantity int

);   

/* CREATE TABLE : SalesDetails */

CREATE TABLE SalesDetails (

SalesID int auto_increment not null primary key,

ProductId int,

SaleDate DateTime,

Quantity int,

TotalBill money,

MarketingLevel Int,

Foreign key(ProductId) references ProductionDetails(ProductId)

);   

/* CREATE TABLE : MarketingDetails */

CREATE TABLE MarketingDetails (

MarketingID int auto_increment not null primary key,

ProductId int,

LaunchDate DateTime,

MarketingExecutive Varchar(255),

UnitPrice money,

Foreign key(ProductId) references ProductionDetails(ProductId)

);   

/* CREATE TABLE : CustomerDetails */

CREATE TABLE CustomerDetails (

CustomerID int auto_increment not null primary key,

FirstName varchar(255),

LastName Varchar(255),

DateOfBirth DateTime,

Address Varchar(255)

);   

/* CREATE TABLE : DeliveryDetails */

CREATE TABLE DeliveryDetails (

DeliveryID Int auto_increment not null primary key,

CustomerId int,

ProductID int,

OrderQuantity Int,

OrderDate DateTime,

DeliveryDate DateTime,

DeliveryStatus Bit,

Foreign key(ProductId) references   ProductionDetails (ProductId),

Foreign key (Customerid) references CustomerDetails    (CustomerId)

);   

/* CREATE TABLE : ManagementDetails */

CREATE TABLE ManagementDetails (

ManagementID int auto_increment not null primary key,

OfficeAddress Varchar(255),

TotalEmployees Int );  

/* Insert Data in ProductionDetails */

Insert into ProductionDetails (ProductName, Manufacturer, ManufacturingDate,   ExpiryDate, UnitPrice, Quantity)

Values (‘Hanging Pathos in Glass container’, ‘ABC Gardening’, ’01-sep-2019’, ’01-sep-2020’, 599, 10)

Insert into ProductionDetails (ProductName, Manufacturer, ManufacturingDate,   ExpiryDate, UnitPrice, Quantity)

Values (‘Peace Lily Red’, ‘ABC Gardening’, ’01-sep-2019’, ’01-sep-2020’, 999, 10)

/* Insert Data in SalesDetails   */

Insert into SalesDetails (ProductId, SaleDate, Quantity, TotalBill, MarketingLevel)

Values (1, ’05-sep-2019’, 1, 599, 1)

Insert into SalesDetails (ProductId, SaleDate, Quantity, TotalBill, MarketingLevel)

Values (2, ’12-sep-2019’, 1, 999, 1)

/* Insert Data in MarketingDetails */

Insert into MarketingDetails (ProductId, LaunchDate, MarketingExecutive, UnitPrice)

Values (1, ’02-sep-2019’, ‘Mr George’, 599)

Insert into MarketingDetails (ProductId, LaunchDate, MarketingExecutive, UnitPrice)

Values (2, ’02-sep-2019’, ‘Mr George’, 999)

/* Insert Data in CustomerDetails */

Insert into CustomerDetails (FirstName, LastName, DateOfBirth, Address)

Values (‘Namrata’, ‘Nikhare’, ’04-Jan-1979’, ‘Besa Nagpur, Maharashtra, India’)

Insert into CustomerDetails (FirstName, LastName, DateOfBirth, ‘Address’)

Values (‘Julie’, ‘Fernandis’, ’17-Apr-2000’, ‘100, street park, New York’)

/* Insert Data in DeliveryDetails */

Insert into DeliveryDetails (CustomerId, ProductID, OrderQuantity, OrderDate, DeliveryDate, DeliveryStatus)

Values (1, 1, 2, ’10-sep-2019’, ’11-sep-2019’, 1)

Insert into DeliveryDetails (CustomerId, ProductID, OrderQuantity, OrderDate, DeliveryDate, DeliveryStatus)

Values (2, 2, 1, ’20-sep-2019’, null, 0)

/* Insert Data in ManagementDetails */

Insert into ManagementDetails (OfficeAddress, TotalEmployees)

Values (‘109, Ozone park, India’, 102)

/* SELECT QUERIES*/

/* Display all tables */

/* We can use MySQL command line client to display all the tables */

/* Below are the commands to display all tables */

/* use operating system command line to connect to MySQL */

$ mysql –u root –p     

/* Connect to database */

Mysql> use SampleProduction;

/* Command to List Tables from current database */

Mysql> show tables;

/* Query to identify sales total for all items */

SELECT SD.ProductID, PD.ProductName, sum(TotalBill) FROM SalesDetails SD

INNER JOIN ProductionDetails PD on SD.ProductID = PD.ProductID

GROUP BY ProductID

/* Identify Delivery confirmation of sold items */

SELECT ProductID, DeliveryStatus FROM DeliveryDetails

/* Identify Marketing level for sold items */

SELECT SD.ProductId, PD.ProductName, SD.Marketinglevel

FROM SalesDetails SD

INNER JOIN ProductionDetails PD on SD.ProductID = PD.ProductID


Related Solutions

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...
Create three MySQL database tables and write SQL scripts to read, insert, and delete data. The...
Create three MySQL database tables and write SQL scripts to read, insert, and delete data. The first database table will contain the names of at least four movies. The second table will be a list of actors who appear in the movies. The third table will be an associative table that describes the relationship between the actors and their movies (which actors appear in which movies). Actors and movies have a “many-to-many relationship,” meaning an actor can be in multiple...
Create three MySQL database tables and write SQL scripts to read, insert, and delete data. The...
Create three MySQL database tables and write SQL scripts to read, insert, and delete data. The first database table will contain the names of at least four movies. The second table will be a list of actors who appear in the movies. The third table will be an associative table that describes the relationship between the actors and their movies (which actors appear in which movies). Actors and movies have a “many-to-many relationship,” meaning an actor can be in multiple...
The following tables form part of a database (Flights Database) held in a relational DBMS: employee...
The following tables form part of a database (Flights Database) held in a relational DBMS: employee (empNo, empName, empSalary, empPosition) aircraft (aircraftNo, acName, acModel, acFlyingRange) flight (flightNo, aircraftNo, fromAirport, toAirport, flightDistance, departTime, arriveTime) certified (empNo, aircraftNo) Where:  employee contains details of all employees (pilots and non-pilots) and empNo is the primary key;  aircraft contains details of aircraft and C is the primary key.  flight contains details of flights and (flightNo, aircraftNo) form the primary key.  certified...
Use MySQL server. First step: create and use database called EDU. Syntax: CREATE SCHEMA edu; USE...
Use MySQL server. First step: create and use database called EDU. Syntax: CREATE SCHEMA edu; USE edu; Create a script which will create the tables listed below: STUDENT(STUDENT_ID, STUDENT_NAME, MAJOR_ID, DOB, PHONE_NUMBER) MAJOR(MAJOR_ID, MAJOR_NAME) ENROLLMENT(STUDENT_ID, COURSE_ID, GRADE) COURSE(COURSE_ID, COURSE_NAME) RESPONSIBILITY(FACULTY_ID, COURSE_ID) TEACHER(FACULTY_ID, DEPT_ID, TEACHER_NAME) DEPARTMENT(DEPT_ID, DEPARTMENT_NAME) Start the script with a series of DROP statements so that as you correct mistakes you will start fresh each time. To avoid referential integrity errors, the table drops should be in the opposite...
Design and implement a relational database application of your choice using MS Workbench on MySQL a)...
Design and implement a relational database application of your choice using MS Workbench on MySQL a) Declare two relations (tables) using the SQL DDL. To each relation name, add the last 4 digits of your Student-ID. Each relation (table) should have at least 4 attributes. Insert data to both relations (tables); (15%) b) Based on your expected use of the database, choose some of the attributes of each relation as your primary keys (indexes). To each Primary Key name, add...
Using the sample.sql script, create the sample database in MySQL. Submit the MySQL interactive screen that...
Using the sample.sql script, create the sample database in MySQL. Submit the MySQL interactive screen that results. create database sample; use sample; create table customer (custno int auto_increment primary key, firstname varchar(20), middle varchar(20), lastname varchar(20), address varchar(60), telnum1 varchar(10), telnum2 varchar(10), telnum3 varchar(10), pin varchar(6), email varchar(30)); create table accttype (id int primary key, type varchar(10)); insert into accttype (id, type) values (1,'check'); insert into accttype (id, type) values (2,'save'); insert into accttype (id, type) values (3,'cd'); insert into...
QUESTION: The following tables describe the content of a relational database: a) Identify and classify the...
QUESTION: The following tables describe the content of a relational database: a) Identify and classify the tables as either entity or relationship The first step in building an E-R model is to identify the entities. Having identified the entities, the next step is to identify all the relationships that exist between these entities. Using the content of the relational database above: b) Using the relations in the relational database, explain how one can transform relationship in E-R model into a...
• 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,...
One of the characteristics of good relational database design is normalized tables. Discuss two ways in...
One of the characteristics of good relational database design is normalized tables. Discuss two ways in which normalization helps minimize data redundancy and anomalies such as insertion, deletion, and update anomalies. What are some other characteristics of good database design?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT