Write the sql code to enter the first two rows for the table

Assignment Help Database Management System
Reference no: EM133692612

Database Management Systems

Learning Objectives

  • Use SQL to create a table manually
  • Use SQL to create a copy of a table using a subquery
  • Manipulate the structure of existing tables to add, modify, and remove columns and constraints
  • Use SQL to do data manipulation (insert, update, and delete rows of data)
  • Use SQL to create database views, including updatable views
  • Use Procedural Language SQL (PL/SQL) to create triggers, stored procedures, and PL/SQL functions
  • Create embedded SQL

Assessment Details: Advanced SQL

Question 1: What type of integrity is enforced when a primary key is declared?

Question 2: Explain why it might be more appropriate to declare an attribute that contains only digits as a character data type instead of a numeric data type.

Question 3: What is a trigger, and what is its purpose? Give an example?

Question 4: The ConstructCo database stores data for a consulting company that tracks all charges to projects. The charges are based on the hours each employee works on each project. The structure and contents of the ConstructCo database are shown in Figure 1.

Figure 1: ConstructCo Database

2159_Advanced SQL.jpg

Given the structure and contents of the ConstructCo database shown in Figure 1, use SQL commands to answer following exercises

a. Download the following file from Moodle: Week 8: 08_ConstructCo_MySQL.txt

b. Import the file 08_ConstructCo_MySQL.txt into XAMPP.

c. Write the SQL code that will create only the table structure for a table named EMP_1. This table will be a subset of the EMPLOYEE table. The basic EMP_1 table structure is summarized in the following table. Use EMP_NUM as the primary key. Note that the JOB_CODE is the FK to JOB so be certain to enforce referential integrity. Your code should also prevent null entries in EMP_LNAME and EMP_FNAME.

ATTRIBUTE (FIELD) NAME              DATA DECLARATION

EMP_NUM                                      CHAR(3)
EMP_LNAME                                   VARCHAR(15)
EMP_FNAME                                   VARCHAR(15)
EMP_INITIAL                                  CHAR(1)
EMP_HIREDATE                               DATE
JOB_CODE                                     CHAR(3)

d. Having created the table structure in 4 (c), write the SQL code to enter the first two rows for the table shown in Figure 2. Each row should be inserted individually, without using a subquery. Insert the rows in the order that they are listed in the figure.

Figure 2 The EMP_1 Table

EMP_NUM EMP_LNAME EMP_FNAME EMP_INITIAL EMP_HREDATE JOB_CODE
401 News  John  G 8-Nov-00 502
102 Senior  Davie H 12-Jul-89 501
103 Arbough  June E 1-Dec-96 500
104 Ramoras  Anne K 15-Nov-87 501
105 Johnson  Alice K 1-Feb-93 502
106 Smithfield  william
22-Jun-04 500
107 Alonzo Maria D 10-Oct-83 500
108 Washington Ralph B 22-Aug-81 501
109 Smith  Larry w 18-Jul-97 501

 

e. Using the EMPLOYEE table that already exists, use a subquery to insert the remaining rows from the EMPLOYEE table into the EMP_1 table. Remember, your sub- query should only retrieve the columns needed for the EMP_1 table and only the employees shown in the figure.

f. Write the SQL code to change the job code to 501 for the person whose employee number (EMP_NUM) is 107.

g. Write the SQL code to delete the row for William Smithfield, who was hired on June 22, 2004, and whose job code is 500. (Hint: Use logical operators to include all of the information given in this problem.)

h. Write the SQL code to create a copy of EMP_1, including all of its data, and naming the copy EMP_2.

i. Using the EMP_2 table, write the SQL code that will add the attributes EMP_PCT and PROJ_NUM to EMP_2. The EMP_PCT is the bonus percentage to be paid to each employee. The new attribute characteristics are:
EMP_PCT NUMBER(4,2) PROJ_NUM CHAR(3)

Note: If your SQL implementation requires it, you may use DECIMAL(4,2) or NUMERIC(4,2) rather than NUMBER(4,2).

j. Using the EMP_2 table, write the SQL code to change the EMP_PCT value to 3.85 for the person whose employee number (EMP_NUM) is 103.

 

Reference no: EM133692612

Questions Cloud

Write the sql code to delete the row for william smithfield : Write the SQL code to delete the row for William Smithfield, who was hired on June 22, 2004, and whose job code is 500. (Hint: Use logical operators
How does science contend with or complement buddhism : How does science contend with or complement Buddhism? Please support your points with supporting evidence.
Write the sql code to change the job code : Write the SQL code to change the job code to 501 for the person whose employee number and Write the SQL code to create a copy of EMP_1, including
What is the purchase process for your companys product : What is the purchase process for your company's product? What stages of the buying process are most critical for the buyers of your product and why?
Write the sql code to enter the first two rows for the table : write the SQL code to enter the first two rows for the table shown in Figure, Insert the rows in the order that they are listed in the figure
How your system problem solves an ethical dilemma : Using thorough Biblical support, write a detailed purpose statement that clearly articulates how your system problem solves an ethical dilemma.
Write the sql code that will create only the table structure : Write the SQL code that will create only the table structure for a table named EMP_1 and Use Procedural Language SQL (PL/SQL) to create triggers
Discuss new testament assertion of jesus as god the son : What are the implications? How did Jesus and His followers communicate this unique relationship between "God the Father" and "God the Son"?
Importance of shabbat and tefillah to jewish adherents : Describe the importance of Shabbat and Tefillah to Jewish adherents.

Reviews

Write a Review

Database Management System Questions & Answers

  Speculate the data exchange and data management trends

Speculate the data exchange and data management trends that may take place in the next five to 10 years. Justify your response.

  Find maximum salary of employees from database table

Find the maximum salary of all employees who are not managers. Give all the managers in the database a 10 percent salary raise. Give all the other employees a 5 percent salary raise.

  What is a trigger in database

Discuss what is a trigger in database, and what is its purpose? Discuss real-word application example of triggers. Please DO NOT write the SQL command.

  Find out all the orders placed by all the customers

Retrieve all details of Orders administered by persons who hold the designation Sales Representative and shipped by United Package

  Create a new database

Create a new database. Add tables based on the design of your entity-relationship diagram from Question 1. Make sure that you:· have the correct primary keys for each table,· add foreign keys,· choose appropriate data types for each field.Paste a scr..

  Identify the primary keys and creating foreign keys

In class practice: Turn each ER diagram into a database diagram by identify the primary keys and creating foreign keys. Insert new columns or tables as needed. Also, if necessary, specify what must be done to enforce maximum and minimum cardinalit..

  Create all the relations in a microsoft access database

COIT20247 Database Design and Development (T12017) Assignment. Create all the relations in a Microsoft Access database

  Find number of items that we offer for sale in each color

Find the number of items that we offer for sale in each color. Find the name and number of all items that have no known weight.

  Small company purchasing database system

A small company allocates a certain amount of dollars to each department to be used to purchase things they need. The approved budget information is kept in the APPROVED-BUDGET file by department number in the purchasing system. When a department det..

  Differentiate databases data warehouse and data mining

Select any mid to large company. Research the following about your company. Determine its mission, vision, and goals. Discuss its IT architecture.

  Highlight the advanced database management elements

Highlight the Advanced Database Management elements. Relate to at least three learning objectives. Critique the article in terms of relevance to your learning objectives.

  Write a query that consists of one block only

Find the ssn and last name of every employee whose ssn contains two consecutive 8's, and has a supervisor. Sort the results by ssn.

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