Write these sql insert statements

Assignment Help Database Management System
Reference no: EM132365094

Database Design and Use Assignment -

Section 1 -

A database analyst has developed the following ER Diagram (attached).

Create a script file named ASS1_SQL.TXT.

Add your Student ID and Student name the first lines of the script file.

1.1. Relationships

Write the English sentences that best describe the ERD above.

Place the text in the specified location in the file: ASS1_SQL.TXT

 Prefix each line with comment symbols -- (two hyphens)

E.g.: --ONE Employee MUST belong to ONE Branch

--ONE Branch MAY employ to MANY Employees

--ONE Branch MUST belong to ONE Organisation

-- ONE Organisation MAY employ to MANY Branches

1.2.Drop Tables

Write SQL DROP statements that will drop all the tables.

1.3. Create Tables

Write SQL CREATE TABLE statements to create all the tables.

Note:

  • All tables must have primary keys.
  • All tables must have appropriate foreign key constraints.
  • Each foreign key column must have identical column name, data type and size of the primary key that it refers to.
  • Add any NOT NULL constraints as dictated by the ERD.
  • The following columns data types and sizes must be used.

custid, prodid, ordid, spid

number(4)

cfirstname, csurname, billingaddress, deliveryaddress, prodname, spfirstname, spsurname

varchar(30)

cgender, spgender

varchar(1)

qtysold, qtydelivered

number(4)

saleprice, currentprice

number(6,2)

The following constraints must be used

Type Details

 

Check

Gender values must be M or F

Check

Prices must be in the range 0 to 5000

Check

Quantities must be in the range 0 - 99

Foreign Key

All foreign keys must have named constraints

1.4. Insert Customers

Write SQL INSERT statements that add the data shown to the CUSTOMER table.

1.5. Check constraint error

Write SQL INSERT statements that attempt to add the data shown to the CUSTOMER table.

This statement must fail due to check constraints.

1.6. Insert Products

Write SQL INSERT statements that add the data shown to the PRODUCT table.

1.7. Check constraint error

Write SQL INSERT statements that attempt to add the data shown to the PRODUCT table. This statement must fail due to check constraints.

1.8. Insert Salespersons

Write SQL INSERT statements that add the data shown to the SALESPERSON table.

1.9. Insert Shop Orders

Write SQL INSERT statements that add the data shown to the SHOPORDER table.

1.10. FK Error

Write these SQL INSERT statements that attempts to add the data shown to the SHOPORDER table. These statements must fail. If they don't fail, there is a problem with your Foreign Key constraint clause in your Create Table statement. Add these statements to the appropriate location within the script file.

1.11. Insert Oder Lines

Write SQL INSERT statements that add the data shown to the ORDERLINE table.

1.12. FK errors

Write these SQL INSERT statements that attempt to add the data shown to the ORDERLINE table. These statements must fail. If they don't fail, there is a problem with your Foreign Key constraint clause in your Create Table statement.

1.13. List rows in all Tables

Write five SQL statements that will list all of the rows in all tables in ascending primary key sequence. Add these statements to the appropriate location within the script file.

Section 2 -

Add each statement to the appropriate location within the script file.

2.1.1 Count the total number of orders in the SHOPORDER table.

2.1.2 Count the total number of orders that have been made by female customers.

2.1.3 Count the total number of orders that have been made by each gender of customer.

2.1.4 List the order id, customer id, firstname & surname for all shop orders where the customer is female. List in ascending customer id / order id sequence

2.1.5 List order id, customer id, firstname & surname, product id and quantity sold for all rows in the ORDERLINE table. List in ascending customer id / order id / product id sequence.

Section 3 -

The database analyst has modified the existing ER Diagram (attached):

Each product is assigned to one or more managers.

It is the responsibility of a manager to perform a quality check once a week on each product that they have been assigned to.

For each quality check performed by a manager, the week no and score (a value between 1 and 3) is recorded.

3.1.Drop Tables

Write SQL DROP statements that will drop all the additional tables. Add these statements to section 1.2 of the script file.

3.2. Create Tables

Write SQL CREATE TABLE statements to create all additional the tables. Add these statements to the appropriate location within the script file.

Note: All tables must have primary keys. All tables must have appropriate foreign key constraints. Each foreign key column must have identical column name, data type and size of the primary key that it refers to. Add any NOT NULL constraints as dictated by the ERD. Choose your own appropriate column data types and sizes.

3.3. Insert Managers

Write SQL INSERT statements that add the data shown to the MANAGER table.

3.4. Insert Allocations

Write SQL INSERT statements for the ALLOCATION table to assign products to managers.

3.5. PK Error

Write these SQL INSERT statements that attempt to add the data shown to the ALLOCATION table. These statements must fail. If they don't fail, there is a problem with your Primary Key constraint clause in your Create Table statement. Add these statements to the appropriate location within the script file.

3.6. Insert Quality Checks

Write SQL INSERT statements for the QUALITYCHECK table to record scores awarded by managers. Add these statements to the appropriate location within the script file.

3.7. PK Error

Write these SQL INSERT statements that attempt to add the data shown to the QUALITYCHECK table. These statements must fail. If they don't fail, there is a problem with your Primary Key constraint clause in your Create Table statement. Add these statements to the appropriate location within the script file.

3.8. FK Error

Write these SQL INSERT statements that attempt to add the data shown to the QUALITYCHECK table. These statements must fail. If they don't fail, there is a problem with your Foreign Key constraint clause in your Create Table statement. Add these statements to the appropriate location within the script file.

3.9. List all rows in additional Tables

Write three SQL statements that will list all of the rows from all additional tables in ascending primary key sequence. Add these statements to the appropriate location within the script file.

Section 4 -

Write these SQL SELECT statements.

Add each statement to the appropriate location within the script file.

4.1. List the order id, product id, product name, current price, sale price and the price difference for all products that appear in the ORDERLINE table. Only list rows where the price difference is greater than 10% of the product's current selling price. List in ascending price difference sequence.

4.2. Use a Union clause to list the names of all customers, salespersons and managers in surname / firstname sequence. Show the role of each person.

4.3. Use a UNION clause to list each order id and address. The list must be in ascending Order ID sequence. If the Shop Order delivery address is NULL, then you must display the customer's billing address instead of the delivery address.

4.4. List the order id, customer id, firstname & surname, product id & name for all rows in the ORDERLINE table. List in ascending customer id / order id / product id sequence.

4.5. List the product id, name and current price of all products that have a selling price greater the average current price of all products. List in ascending current price sequence.

Section 5 -

5.1. For each row in the SHOPORDER table, show the customer id & surname and order id. Ensure that every customer is the CUSTOMER table is listed - even if they have not created any shop orders. List in ascending customer id / order id sequence.

5.2. Count the number of shop orders for each customer. Ensure that every customer is the CUSTOMER table is listed - even if they have not created any shop orders. List in ascending customer id.

5.3. List order id, customer id, firstname & surname, product id and quantity sold for all rows in the ORDERLINE table. List in ascending customer id / order id / product id sequence.

5.4. List the product id, product name and total quantity sold for all products that appear in the ORDERLINE table. List in ascending total sequence / product id.

5.5. Same as above, but only show products where total sales are in the range 2 to 10 (inclusive)

5.6. Same as above, but only show products where total sales are greater than 1 that contain the word 'Lamp' or 'Table' in the product name.

5.7. List the average score in the QUALITY CHECK table for each product. Only show results if the average score is greater than or equal to 2.0. List an ascending average score sequence.

5.8. List the total orders for products with an average quality check score greater than or equal to 2.0. Do not 'hard code' product ids 33 and 31 in your query as obviously data values will change over time.

Attachment:- Database Design and Use Assignment File.rar

Verified Expert

The database of the customer relationship management system has been developed. The dummy data has been inserted into the system. The create and delete statements are provided for system.

Reference no: EM132365094

Questions Cloud

Calculate the end-of-year loan payment : Calculate the end-of-year loan payment - Prepare a loan amortization schedule showing the interest and principal breakdown of each of the three loan payments
Customer service at Pret A Manger : What are the advantages and disadvantages of Pret A Manger organizing itself so that the individual shops make the sandwiches that they sell?
Whether the commercial is using logos to market to consumers : Explain whether the commercial is using logos, ethos, or pathos to market to consumers and Explain why the commercial was successful
Why is separate system security plan required : CSIA 413-"Why is a separate System Security Plan (SSP) required for each field office?" (Or, put another way "Why doesn't one size fits all work for SSP's?")
Write these sql insert statements : Write SQL INSERT statements that attempt to add the data shown to the CUSTOMER table - Write SQL INSERT statements that add the data shown to the SALESPERSON
Presents strategy for communicating new social media : Prepare one page briefing statement for company's CISO that presents strategy for communicating new "social media" policy to field office employees-and managers
Create a competitor analysis grid : Create a competitor analysis grid that includes company information, product/service information, customer information, and sources of competitive advantage
Assessment of the IT policy system : CSIA 413-Prepare one page briefing statement for IT Governance board of Red Clay Renovations which explains the purpose of the audit
Dod cybersecurity culture and compliance initiative : Choose one of policy implementation documents from this week's readings DHS Risk Management Fundamentals OR DoD Cybersecurity Culture and Compliance Initiative.

Reviews

Write a Review

Database Management System Questions & Answers

  Describe the oracle software file structure

Describe ASM in your environment. You may use ASM, or not. But identify the ASM architecture and implementation. If you don't use ASM, then support

  Phase of database development

Entity Relationship Diagrams are input to the phase of Database Development - The attribute Empdeptno is a foreign key referring to the department number (Deptno. of the table Department.

  Analyse and comprehend a provided er diagram

Analyse and comprehend a provided ER diagram and Database Schema and to implement a database based on the provided ER diagram and Database Schema

  What is the role of a dbms

What is the role of a DBMS, and what are it advantages? What are its disadvantages?

  Advantages and disadvantages of joins and nested queries

One side effect of normalization is that you often need more than one table to get meaningful results. For example, you may have a table that includes a list of parts and the ID number for the vendor of each part. T

  Describe the objectives of the database environment

Analyze the database environment - describe the problems and constraints and describe the objectives of the database environment.

  Analysis of a simple case study

VSS has an existing software package that controls its high bay systems and wants to rewrite it. The existing system is written in C and uses C-ISAM files to store data.

  Identify the purpose of the project and the data model

Provide the background information of the data model to be developed. Identify the purpose of the project and the data model.

  Design a database structure that captures information

Design a database structure that captures/tracks information of researchers within all universities in a given state.

  Use a two-dimensional array to accumulate the number

Create a form containing labels with each of the questions and a group of radio buttons for each question with the following responses: Always, Usually, Sometimes, Seldom, Never.

  Key value of fourth index record on top level

What is the key value of the 4th index record on the top level, assuming each index record points to the record with the highest key value in a block of the next level down?

  Create all the tables with identified constraints on oracle

SIT103 – Database and Information Retrieval - Create all the tables with identified constraints on Oracle

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd