Write an sql drop statements that will drop the all tables

Assignment Help PL-SQL Programming
Reference no: EM13907637

Section 1:

A database analyst has developed the following ER Diagram:

948_ER Diagram.png

Create a file named ASS2_9999999.sql (where 9999999 must be replaced with your student id).

Write an SQL DROP statements that will drop the all tables. Add these statements to the appropriate location within the script file.

Write a SQL CREATE TABLE statement to create the EMPLOYEE & ACTIVITY tables. Add the statement to the appropriate location within the script file. Note:

• The table must have a primary key.
• The following columns data types and sizes must be used:

empid, actid, yearsservice

Integer(4)

empname, status, description

Varchar(30)

empgender,  categorycode

Varchar(1)

Write SQL INSERT statements that add the data to the EMPLOYEE & ACTIVITY tables based on the information below. Add the SQL statements to the appropriate location within the script file.

Employee Id

Name

Gender

Status

YearsService

1

Clyde

M

International

2

2

Sally

F

Local

9

3

Imogen

F

International

4

4

James

M

Local

3

5

Tara

F

International

6

6

Mike

M

Local

8

7

Kerri

F

Local

5

8

Emma

F

International

3

Activity Id

Description

Category

151

Web Design

A

155

Python Coding

A

163

Sales and Marketing

B

165

Testing

C

171

Documentation

C

174

Telephone Support

C

Write a SQL CREATE TABLE statement to create the ALLOCATION table. Add the SQL statement to the appropriate location within the script file. Note:
• The table must have a primary key constraint matching the requirements of the ERD
• The table must have the appropriate foreign key constraint.
• The 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
• A check constraint named CK_ALLOCATION_RATE must be created to ensure that the HourlyRate value is in the range 0.00 to 299.99

Write SQL INSERT statements that add the data shown to the ALLOCATION table. Add the SQL statements to the appropriate location within the script file.

Employee Details

Activity Details

Agreed Hourly Rate

1

Clyde

163

Sales and Marketing

$45.50

2

Sally

155

Python Coding

$30.00

5

Tara

165

Testing

$30.00

3

Imogen

163

Sales and Marketing

$65.00

5

Tara

155

Python Coding

$27.00

5

Tara

151

Web Design

$25.00

2

Sally

165

Testing

$25.00

1

Clyde

151

Web Design

$50.75

7

Kerri

163

Sales and Marketing

$40.00

6

Mike

151

Web Design

$33.00

Write a single SQL Query statement to that lists the Employee name, Activity description and hourly rate for each row in the ALLOCATION table. This statement will use data from three tables. You must use inner joins.

Primary Key / Foreign key constraint testing If you have written your primary key and foreign key constraints correctly, the following data will be rejected.

Employee Id

Activity Id

Agreed Hourly Rate

1

163

100

5

155

99

If they don't fail, there is a problem with your Primary Key and or Foreign Key constraint clauses in your Create Table statement.

(Optional) Check constraint testing If you have written check constraints, the following data will be rejected.

Employee Id

Activity Id

Agreed Hourly Rate

1

155

500

6

171

399

Queries For each of the following tasks.

Write a single SQL statement that lists the average years of service of all rows in the Employee table. The Heading for the column must be "Avg years of service".

Write a single SQL statement that lists the total number of rows in the Allocation table. The Heading for the column must be "Total Allocations".

Write a single SQL statement that uses a Group By clause that counts the total Allocations for each Activity Category ( these values do not necessarily match table data)

Write a single SQL statement that uses a Group By clause that counts the total Allocations for each Gender ( these values do not necessarily match table data)

Write a single SQL statement that uses the Group By that counts the number of each gender within each status type for all Employees. The list must be in ascending Status Type / Gender sequence. ( these values do not necessarily match table data)

Section 2:

The ER Diagram used earlier has now been modified.

1182_ER Diagram1.png

Write the Drop Table statement for the Action table and add it to the other Drop Table statements that you created in section 1.2 above. Note: The tables containing the foreign keys must be dropped first.

Write Create Table SQL statements for the Action table. Add these statements to the appropriate location within the script file.

• The table must have an appropriate primary key.
• The table must have the appropriate foreign key constraints.
• Each foreign key column must have identical column name datatype and size of the primary key that it refers to
• The following columns datatypes and sizes must be used

weekno number(2)
hrsworked number(4,1)

Write SQL Insert statements to add the following data to the Action table based on the information supplied below (Note: The number of columns and the names of columns below does not match the Action table you have created. You need to decide what data is appropriate for the Action table). Add the SQL statements to the appropriate location within the script file.

Employee Details

Activity Details

Week Number

Hours Worked

1

Clyde

163

Sales and Marketing

39

10

1

Clyde

163

Sales and Marketing

40

8

1

Clyde

163

Sales and Marketing

42

6

1

Clyde

151

Web Design

41

5

1

Clyde

151

Web Design

42

5.5

2

Sally

155

Python Coding

39

10

2

Sally

165

Testing

39

15

2

Sally

155

Python Coding

42

10

2

Sally

165

Testing

40

20

2

Sally

155

Python Coding

41

10

5

Tara

155

Python Coding

39

8

5

Tara

155

Python Coding

40

6

5

Tara

155

Python Coding

41

5

5

Tara

151

Web Design

42

11.5

6

Mike

151

Web Design

39

1

6

Mike

151

Web Design

40

1

6

Mike

151

Web Design

41

1

2.4 Testing Primary Key & Foreign Key constraints. Write SQL INSERT statements that attempt to add the data shown to the ACTION table. Add the SQL statements to the appropriate location within the script file. If you have written your primary key and foreign key constraints correctly, the following data will be rejected.

Employee Id

Activity Id

Week Number

Hours Worked

1

171

43

5

10

163

40

2

3

155

40

10

5

188

39

10

1

163

39

2

5

151

42

6

All of these statements must fail. If they don't fail, there is a problem with your Primary Key and/or Foreign Key constraint clauses in your Create Table statement.

For each of the following tasks, add an SQL statement to the appropriate location within the script file.

List Action data. List all rows in the Action table in ascending primary key sequence Show these columns only: Employee Id, Employee Name, Activity Id, Activity Name, WeekNo, HrsWorked

This query will require you to join multiple tables with inner joins.

Queries For each of the following tasks, add an SQL statement to the appropriate location within the script file.

Based on rows in the Action table Write the query that shows: Employee Id, Employee Name, Week Number, Activity Number, Hours Worked, Total Pay

Note: Total Pay is (HrsWorked * HourlyRate for the Activity)
The list must be in Employee ID / Week Number / Activity Number ascending sequence

Based on rows in the Action table Write the query that shows: Employee Id, Employee Name, Week Number, Total Pay

Note: Total Pay is (HrsWorked * HourlyRate for the Activity)
The list must be in Employee ID / Week Number in ascending sequence

Based on rows in the Action table Write the query that shows: Employee Id, Employee Name, Total Pay

Note: Total Pay is (HrsWorked * HourlyRate for the Activity) The list must be in Employee ID ascending sequence

Based on rows in the Action table Display the total pay for each week number: WeekNo, Total Pay

Note: Total Pay is (HrsWorked * HourlyRate for the Activity) The list must be in Week No in ascending sequence

Based on rows in the Action table Display the total number of hours and total amount paid by each Activity. Activity Id, Activity Description, Total Hours, Total Pay

Note: Total Pay is (HrsWorked * HourlyRate for the Activity)
• This list must be displayed in ascending Activity Id sequence
• Do not display Activities that have zero hours.

Display every Employee and the total number of hours worked by that Employee. Show these columns: Employee Id, Employee Name, Total Hours

• This list must be displayed in ascending Employee Id sequence
• You must include all Employees even if they have not worked any hours.

Section 3

The ER Diagram used earlier has now been modified.

584_ER Diagram2.png


Write the Drop Table statement for Supervisor table and add it to the other Drop Table statements that you created in section 1.2 above. Note: The tables containing the foreign keys must be dropped first.

Write Create Table SQL statements for the Supervisor table. Add the SQL statements to the appropriate location within the script file.

• The table must have an appropriate primary key.
• The table must have the appropriate foreign key constraints.
• Each foreign key column must have identical column name datatype and size of the primary key that it refers to
• The following columns datatypes and sizes must be used
• Use a check constraint named CHK_SUPERVISOR_GENDER to ensure that the gender value must be either M or F.
• Use a check constraint named CHK_SUPERVISOR_ID to ensure that the supid is a value in the range 70 to 150.

suprid

number(3)

supgender

varchar(1)

supname, expertise

varchar(30)

Write SQL Insert statements for the additional tables. Add these statements to the appropriate location within the script file.

Supervisor Id

Supervisor Name

Supervisor Gender

Areas of Expertise

Activities Supervised

71

Sue

 

Counselling

163

 

 

F

Negotiating

 

72

Fred

M

Analysis

151

 

 

 

 

155

73

Mike

 

Motivation

163

 

 

M

Analysis

171

74

Lilly

 

Negotiating

163

 

 

F

Motivation

165

 

 

 

 

171

75

Tara

 

Training

151

 

 

F

Counselling

155

 

 

 

Motivation

171

76

Albert

M

Analysis

 

Section 4

(optional) Testing Check constraints. Write SQL INSERT statements that attempt to add the data shown to the SUPERVISOR table. Add these statements to the appropriate location within the script file. If you have implemented check constraints, the following data will be rejected.

Supervisor Id

Supervisor Name

Supervisor Gender

50

Ben

M

81

Kurt

X

Queries For each of the following tasks, add a single SQL statement to the appropriate location within the script file.

List the total number of Employees allocated to each Supervisor

• Show the Supervisor name and the total number of Employees value
• This list must be in ascending Supervisor name sequence.

For each Activity, list every Supervisor expertise associated with that Activity

• Show the Activity Name and the Expertise value
• This list must be in ascending Activity Name / Expertise sequence.
• Ensure that the result set does not contain any duplicate rows.

List only those Employees whose total hours worked is greater than the average hours worked. You must use a subquery in your solution.

• Show the Employee id, Employee name and the total hours worked
• This list must be in descending total hours worked sequence.

Write a single SQL statement to list every employee id, name and gender for those employees who have worked on the activity that has the highest Total Pay. You must use a subquery in your solution.

(Note: Obviously the activity that has the highest pay could change as additional data is inserted. Your query must be able to deal with such changes without the need to alter the SQL code. This note isn't here to scare you, it's simply means don't use code such as ...where actid = 151... ).

• This list must be in ascending Employee id sequence.

List all employee names & genders and all Supervisor names & genders in a single list.

• Indicate which people are Employees and which people are Supervisors.
• You must use a union in your solution.
• The list must be in ascending name sequence

Reference no: EM13907637

Questions Cloud

What other dbms constructs came after relational databases? : What other DBMS constructs came after relational databases?
Kenya company standard cost accounting system recorded : Kenya Company's standard cost accounting system recorded this information from its June operations.
Compute the sum of the first : Assume there is a variable , h already associated with a positive integer value. Write the code necessary to compute the sum of the first h perfect squares, starting with 1 .
Program that generates a new list : Given a list listA of numbers, write a program that generates a new list listB with the same number of elements as listA, such that each element in the new list is the average of its neighbors and itself in the original list. For example, if listA..
Write an sql drop statements that will drop the all tables : Write an SQL DROP statements that will drop the all tables. Add these statements to the appropriate location within the script file - Write a SQL CREATE TABLE statement to create the ALLOCATION table. Add the SQL statement to the appropriate locati..
Analysis of flexible budgets and standard costs emphasizes : Analysis of flexible budgets and standard costs emphasizes the importance of a similar unit of measure for meaningful comparisons and evaluations.
Program that loads the keywords and definitions : 1) Develop the part of the program that loads the keywords and definitions from the external file
Folsom custom skis as discussed in the chapter opener : Folsom Custom Skis, as discussed in the chapter opener, uses a costing system with standard costs for direct materials,
Differentiate between scope verification and scope control : "Differentiate between scope verification and scope control of the Microsoft NT conversion project". Justify the importance of scope verification and scope control for the success of the project

Reviews

Write a Review

PL-SQL Programming Questions & Answers

  Write a query to display the name

Write a Query to display the name, department_id of the employee that earns the highest salary in the Employees table.

  Assignment of sql queries

Design a query to find out details of CustomerNo, first name , last name who have paid amount more than the average amount paid by all customers.

  Identify the choice that best completes the statement

Based upon the contents of the BOOKS table, which of the following SQL statements will display the retail price for two copies of each book currently in inventory?

  Script that creates and calls a stored

Write a script that creates and calls a stored procedure named spInsertProduct that inserts a row into the Products table. This stored procedure should accept five parameters

  Ilab sql queries using mysql

The purpose of this iLab is to prepare for the first phase of the Course Project. This week, you will learn to create and run SQL SELECT queries from a script  in the MySQL database. You will need to create a database in MySQL via Omnymbus, run a ..

  Pl-sql block to display last name and salary

Write a PL/SQL block that displays the last name and salary of the following people. Each of these can be done separately as PL/SQL, first to test and get the output lines then encapsulated.

  Create tables using sql ddl

Write the SQL DDL to create the database that contains each of the relations shown in the above ERD. You will need to provide - Your DDL code for each table that you create and a screenshot showing each table that is created.

  Write a pl/sql solution that displays the registration

Write a PL/SQL solution that displays the registration and the maximum and the minimum miles travelled by a car during the rental period for all the bookings where the booking has been paid for.

  Draw an entity-relationship diagram

Draw an Entity-Relationship Diagram (ERD) for the data storage requirements of a business described in the case study and Data Model Transformation.

  Select statement without a from clause

Write a SELECT statement without a FROM clause that creates a row with these columns To calculate the fourth column, add the expressions you used for the first and third columns.

  Create program to enter first and second number

Create a program that enters first and a second number. The first and second number that will be entered should be computed in halves, quarter, double, and square.

  An er diagram for the system

An ER diagram for the system. Show all entities, relationships, cardinalities and optionalities. Also, include all intersection entities. You must use the Finkelstein methodology as per the study book and tutorials.

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