Docsity

SQL Code for Creating and Modifying Tables and Data, Lecture notes of History of the Balkans

Toggle sidebar
bg1
Course Project
DeVry University
College of Engineering and Information Sciences
Course Number: MIS582
Course Project Deliverable: 5
Name: Markus Davis
Include screenshots of the code and result
Problem 1
Write the SQL code that will create only the table structure for a table namedEMPLOYEE. The basic
table structure is summarized in the following table. UseEMP_NUMas the primary key. Your code should
also prevent null entries inEMP_LNAMEandEMP_FNAME.
Problem 2
Having created the table structure inProblem 1, write the SQL code to enter the first five
rows for the table shown inthe following figure. Each row should be inserted
individually, without using a subquery. Insert the rows in the order that they are listed in
the figure. Take a screenshot of the code and data entered.
pf3
pf4
pf5
pf8

Partial preview of the text

Download SQL Code for Creating and Modifying Tables and Data and more Lecture notes History of the Balkans in PDF only on Docsity!

Course Project

DeVry University

College of Engineering and Information Sciences

Course Number: MIS Course Project Deliverable: 5 Name: Markus Davis Include screenshots of the code and result Problem 1 Write the SQL code that will create only the table structure for a table named EMPLOYEE. The basic table structure is summarized in the following table. Use EMP_NUM as the primary key. Your code should also prevent null entries in EMP_LNAME and EMP_FNAME. Problem 2 Having created the table structure in Problem 1 , write the SQL code to enter the first five rows for the table shown in the following f igure. Each row should be inserted individually, without using a subquery. Insert the rows in the order that they are listed in the figure. Take a screenshot of the code and data entered.

INSERT INTO EMPLOYEE VALUES ('101','News','John','G','200-11-08','502'); INSERT INTO EMPLOYEE VALUES ('102','Senior','David','H','1989-07-12','501'); INSERT INTO EMPLOYEE VALUES ('103','Arbough', 'June', 'E','1996-12-01','500'); INSERT INTO EMPLOYEE VALUES ('104','Ramoras','Anne','K','1987-11-15','501'); INSERT INTO EMPLOYEE VALUES ('105','Johnson','Alice','K','1993-02-01','502'); INSERT INTO EMPLOYEE VALUES ('106','Smithfield','William',NULL,'2004-06- 22','500'); INSERT INTO EMPLOYEE VALUES ('107','Alonzo','Maria','D','1993-10-10','500'); INSERT INTO EMPLOYEE VALUES ('108','Washington','Ralph','B','1991-08- 22','501'); INSERT INTO EMPLOYEE VALUES ('109','Smith','Larry','W','1997-07-18','501') Problem 3 Write the SQL code to change the job code to 501 for the person whose employee number (EMP_NUM) is 103. UPDATE EMPLOYEE SET JOB_CODE=’501’

Problem 5 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). ALTER TABLE EMP_2 ADD EMP_PCT DECIMAL(4,2), ADD PROJ_NUM CHAR(3); SELECT * FROM EMP_2; Problem 6 Using the EMP_2 table, write a single SQL command to change the EMP_PCT value to 5.00 for the people with employee numbers 101, 105, and 107 (hint: use the IN keyword). UPDATE EMP_

SET EMP_PCT=‘5.00’

WHERE EMP_NUM IN (101,105,107);

Problem 7 Write the SQL code to join the PRODUCT and VENDOR tables using common attributes. Display the result sorted by price. SELECT * FROM PRODUCT INNER JOIN VENDOR USING (V_Code) ORDER BY P_PRICE ASC;

Problem 9 Write the SQL code to display the customer last name, first name, invoice date, and line price from CUSTOMER, INVOICE, LINE. Join all three tables and display only those values with a line price less than 10. SELECT CUS_LNAME, CUS_FNAME, INV_DATE, LINE_PRICE FROM CUSTOMER, INVOICE, LINE_PRICE WHERE LINE_PRICE < 10; Problem 10

Write a query to count the number of customers with a balance of more than $500. SELECT COUNT(*) FROM CUSTOMER WHERE CUS_BALANCE > 500;