CCS0021L (Information Management) (F4-Formative) Formative Assessment 4
CCS0021L (Information Management) (F4-Formative) Formative Assessment 4
CCS0021L
(INFORMATION MANAGEMENT)
[F4-FORMATIVE]
Formative Assessment 4
EXERCISE
7
DATA MANIPULATION LANGUAGE
Section: DO21
Professor: Mr. Tim Jamison Awat
•
• Inserting a record that has some null attributes requires identifying the fields that actually get data
UPDATE
• Modify existing values in a table with the UPDATE statement:
UPDATE table
SET column = value [, column = value, ...]
[WHERE condition];
SELECT
• Used for queries on single or multiple tables
• Clauses of the SELECT statement:
– SELECT
Syntax:
SELECT AVG(column_name) FROM table_name;
SELECT min(column_name) FROM table_name;
SELECT max(column_name) FROM table_name where [condition];
Example:
SELECT * FROM Products
WHERE Price BETWEEN 10 AND 20;
The following SQL statement selects all products with a price BETWEEN 10 and 20, but products with a CategoryID of 1,2, or 3
should not be displayed:
Example
SELECT * FROM Products
WHERE (Price BETWEEN 10 AND 20)
AND NOT CategoryID IN (1,2,3);
The SQL LIKE Operator
The LIKE operator is used to search for a specified pattern in a column.
Tip: The "%" sign is used to define wildcards (missing letters) both before and after the pattern. You will learn more about
wildcards in the next chapter.
The following SQL statement selects all customers with a City ending with the letter "s":
Example:
SELECT * FROM Customers
WHERE City LIKE '%s';
DELETE
Removes rows from a table
Delete certain rows
DELETE FROM CUSTOMER_T WHERE CUSTOMERSTATE = ‘HI’;
TRUNCATE Statement
• Removes all rows from a table, leaving the table empty and the table structure intact.
• It is a data definition language (DDL) statement rather than a DML statement; cannot easily be undone.
SAVEPOINT
• Create a marker in the current transaction by using the SAVEPOINT statement.
ROLLBACK
• Discard all pending changes by using the ROLLBACK statement.
• Roll back to the marker by using the ROLLBACK TO SAVEPOINT statement.
COMMIT
• Save the changes made permanently in the database by using COMMIT.
Instructions:
Make sure you finish Exercise 6 on F3-formative before doing this.
Connect your SQL developer to your Oracle Cloud Account and write the DML code the show the following. Then for
each number, copy and paste the code including the screenshot of the output.
Queries:
1. Show the employee id, first name, and last names of employees who are managed by manager id
114.
SELECT employee_id, first_name, last_name FROM EMPLOYEES
WHERE manager_id = 114
4. Show all the columns of the departments table that has no manager id.
SELECT * FROM DEPARTMENTS
WHERE manager_id IS NULL
7. Show the job id and the number of employees that has a job id of SA_REP or ST_CLERK. Group
it by job id and arrange it by its job id.
SELECT job_id, phone_number FROM EMPLOYEES
WHERE job_id IN ('SA_REP ','ST_CLERK')
GROUP BY job_id, phone_number
8. Show the job ids and average salaries per job id of the employees table, group it based on job id.
Show only the job ids that has average greater than 10,000, and arrange it based on job id.
SELECT job_id, AVG(salary) FROM EMPLOYEES
GROUP BY job_id HAVING AVG(salary) > 10000
15. Restore the deleted record (employee id 500) back to the employees table.
ROLLBACK TO SPEmp500;
16. Create a view that has all the details of the employees table.
Create view employee_details as
Select * from employees;
VIII. REFERENCES
• Hoffer, J.A., Prescott, M.B., McFadden, F.R. (2007). Modern Database Management 8th
Edition. New Jersey: Pearson Prentice Hall.
8
ADVANCED SQL
Section:
Professor:
Write the appropriate SQL statement for the following queries. The result of the queries will be checked from your
computer.
• Join–a relational operation that causes two or more tables with a common domain to be combined into a
single table or view
• Equi-join–a join in which the joining condition is based on equality between values in the common columns;
common columns appear redundantly in the result table
• Natural join–an equi-join in which one of the duplicate columns is eliminated in the result table
• Outer join–a join in which rows that do not have matching values in common columns are nonetheless
included in the result table (as opposed to inner join, in which rows must have matching values in order to
appear in the result table)
• Union join–includes all columns from each table in the join, and an instance for each row of each table
• The common columns in joined tables are usually the primary key of the dominant table and the foreign key
of the dependent table in 1:M relationships.
Example:
1. Write a query for the HR department to produce the addresses of all the departments. Use the LOCATIONS
and COUNTRIES tables. Show the location ID, street address, city, state or province, and country in the
output. Use a NATURAL JOIN to produce the results.
4. Create a report to display employees’ last name and employee number along with their manager’s last
name and manager number. Label the columns Employee, Emp#, Manager, and Mgr#, respectively.
7. The HR department needs a query that prompts the user for an employee last name. The query then
displays the last name and hire date of any employee in the same department as the employee whose
name they supply (excluding that employee). For example, if the user enters Zlotkey, find all employees who
work with Zlotkey (excluding Zlotkey).
11. Create a report for HR that displays the last name and salary of every employee who reports to King.
• Hoffer, J.A., Prescott, M.B., McFadden, F.R. (2007). Modern Database Management 8th
Edition. New Jersey: Pearson Prentice Hall.