Professional Documents
Culture Documents
CCS0021L
(INFORMATION MANAGEMENT)
[F5-FORMATIVE]
Formative Assessment 5
EXERCISE
9
DATA CONTROL LANGUAGE
Rollen A.Rivera
Student Name
AB21
Section:
Sir Mark Sabili
Professor:
• 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
Figure 7-2
Visualization of different join types with
results returned in shaded area
Scenario
Team up with other students for this exercise about controlling access to database objects.
Task
Write the appropriate SQL statement for the following queries. The result of the queries will be checked from your
computer.
1. What privilege should a user be given to log on to the Oracle server? Is this a system privilege or an object privilege?
- The CREATE SESSION system privilege
3. If you create a table, who can pass along privileges to other users on your table?
- You can, or anyone you have given those privileges to by using the WITH GRANTOPTION.
4. You are the DBA. You are creating many users who require the same system privileges. What should you use to make
your job easier?
Create a role containing the system privileges and grant the role to the users
6. User1 is the owner of the EMP table and grants the DELETE privilege to User2 by using the WITH GRANT OPTION
clause. User2 then grants the DELETE privilege on EMP to User3. User1 now finds that User3 has the privilege and
revokes it from User2. Which user can now delete from the EMP table?
- User1 only
7. You want to grant SCOTT the privilege to update data in the DEPARTMENTS table. You also want to enable SCOTT
to grant this privilege to other users. What command do you use?
GRANT UPDATE on departments TO Scott WITH GRANT OPTION
8. Grant another user query privilege on your table. Then, verify whether that user can use the privilege. Note: For this
exercise, team up with another group. For example, if you are user ora21, team up with another user ora22.
a. Grant another user privilege to view records in your REGIONS table. Include an option for this user to further
grant this privilege to other users.
GRANT UPDATE on departments TO Scott WITH GRANT OPTION
b. Have the user query your REGIONS table.
SELECT * FROM Regions;
c. Have the user pass on the query privilege to a third user (for example, ora23).
SELECT * FROM Regions;
d. Take back the privilege from the user who performs step b.
SELECT * FROM Regions;
10. Take back the privileges on the COUNTRIES table granted to another user.
GRANT select, update, insert ON Countries TO;
13. Add a new row to your DEPARTMENTS table. Team 1 should add Education as department number 500. Team 2
should add Human Resources as department number 510. Query the other team’s table.
Team 1 executes this INSERT statement.INSERT INTO departments(department_id, department_name)
VALUES (500,’Education’);COMMIT;- Team 2 executes this INSERT statement.INSERT INTO
departments(department_id, department_name) VALUES (510,’Administration’);COMMIT;
15. Query all the rows in the other team’s DEPARTMENTS table by using your synonym.
CREATE SYNONYM team2 FOR <user2>.DEPARTMENTS;- Team 2 creates a synonym named team1:
17. Remove the row you inserted into the DEPARTMENTS table in step 13 and save the changes.
VIII. REFERENCES
Hoffer, J., Ramesh, V., Topi, H. (2013). Modern Database Management 11 th Edition, Prentice Hall.
Singh, P., Pottle, B. (2009). Oracle Database 11g: SQL Fundamentals I, Oracle.
10
INTRODUCTION TO PL/SQL AND OTHER SCHEMA
OBJECTS
Rollen A. Rivera
Student Name
AB21
Section:
Sir Mark Sabili
Professor:
In order to accomplish this exercise, the student must have a clear understanding of the following topics:
Create simple and complex views.
Retrieve data from views.
Create, maintain, and use sequences.
Create and maintain indexes.
Create private and public synonyms.
1. Create a view that would contain the department id and department name of the departments table, wherein
the manage id is null. Name this view as DeptIDName.
SOURCE CODE:CREATE VIEW DeptIDName ASSELECT department_id, department_name FROM
departmentsWHERE manager_id IS NULL
2. Create view that would contain the employee id, first name, last name, salary of the employee, including his/
her department name and job title of employees that has an employee id that starts with 200 and above.
Name this view as EMPLOYEE_DET.
SOURCE CODE:CREATE VIEW DeptIDName ASSELECT department_id, department_name FROM
departmentsWHERE manager_id IS NULL
3. Write the code the show the content of the view EMPLOYEE_DET.
SOURCE CODE: SELECT * FROM EMPLOYEE_DET
4. Create a view that would contain the street address, postal code, city, and state province of the countries
Brazil, Belgium and Mexico. Name this view as AddressofCountries.
SOURCE CODE:CREATE VIEW AddressofCountries ASSELECT l.Street_Address, l.Postal_Code, l.City,
l.State_Province FROM locations lINNER JOIN countries C ON l.Country_id = C.country_id WHERE
C.Country_Name IN('Brazil','Mexico','Belgium')
5. Edit the view AddressofCountries. Create an alias for each columns of the view. Here are the aliases:
Street address = ST
Postal Code = PC
City = City
State Province = S_Province
7. Using the new sequence Dept_Seq1, insert a new record on the departments table using the sequence as the
department id value.
SOURCE CODE:INSERT INTO departmentsVALUES (dept_seq1.NEXTVAL,'KennethFrancisco',101,NULL);
8. Change the starting number of Dept_Seq1. The sequence should start at 700.
SOURCE CODE:INSERT INTO departmentsVALUES (dept_seq1.NEXTVAL,'KennethFrancisco',101,NULL);
9. Create an index to optimize the column of the Commision PCT in the employees table. Name this index as
INDEX_comm.
SOURCE CODE:INSERT INTO departmentsVALUES (dept_seq1.NEXTVAL,'KennethFrancisco',101,NULL);
10. Create a synonym for the table countries. Name this synonym as BANSA.
SOURCE CODE:INSERT INTO departmentsVALUES (dept_seq1.NEXTVAL,'KennethFrancisco',101,NULL);
1. What are the parts of a PL/SQL block? Define each ones purposes?
The block is the most fundamental program unit in PL/SQL. The phrasesDECLARE, BEGIN, EXCEPTION, and END
define a PL/SQL block. Variables,cursors, and user-defined functions are all included in DECLARE. SQL andPL/SQL
statements are included in BEGIN. The EXCEPTION includes all stepsthat must be taken when mistakes occur. Finally, we use
Close to indicatethat the program has come to an end.The PL/SQL block is divided into three sections and these are:
● Declaration-It is where you declare variables, allocate memory for cursors, and definedata types.
● ExecutableBEGIN is the first keyword and END is the last keyword. Even if it's simplythe NULL statement, which accomplishes
nothing, it must have at least oneexecutable statement.
● Exception Handling Sections-It is where you catch and handle exceptions raised by the code in theexecution
section. Also starts with the keyword EXCEPTION. It is where youcatch and handle exceptions raised by the code in the
execution section.Also starts with the keyword EXCEPTION.
Hoffer, J., Ramesh, V., Topi, H. (2013). Modern Database Management 11 th Edition, Prentice Hall.
Singh, P., Pottle, B. (2009). Oracle Database 11g: SQL Fundamentals I, Oracle.
11
WRITNG EXECUTABLE STATEMENTS
Rollen A. Rivera
Student Name
AB21
Section:
Sir Mark Sabili
Professor:
In order to accomplish this exercise, the student must have a clear understanding of the following topics:
Declare and use variables.
Declare, use, and print bind variables.
Integrate SQL statements with PL/SQL program constructs.
Write, test, and execute PL/SQL blocks.
SOURCE CODE:
DECLARE_today DATE := SYSDATE;v_tomorrow v_today %TYPE :=SYSDATE+1;
BEGINDBMS_OUTPUT.PUT_LINE('Hello World'); DBMS_OUTPUT.PUT_LINE('TODAY IS: '|| v_today);
DBMS_OUTPUT.PUT_LINE('TOMORROW IS: '|| v_tomorrow); END;
3. Edit lab_02_02_soln.sql.
a. Use single-line comment syntax to comment the lines that create the bind variables.
b. Use multiple-line comments in the executable section to comment the lines that assign values to the bind
variables.
VIII. REFERENCES
Hoffer, J., Ramesh, V., Topi, H. (2013). Modern Database Management 11 th Edition, Prentice Hall.
Singh, P., Pottle, B. (2009). Oracle Database 11g: SQL Fundamentals I, Oracle.