Section15 Practice

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 30

Practice: SECTION 15

Section 15.1

1. What are three uses for a view from a DBA’s perspective?


- Views restrict access and display selective columns
- Views can be used to reduce the complexity of executing queries based on more
complicated SELECT statements.
- Views can be used to retrieve data from several tables, providing data independence
for users.
2. Create a simple view called view_d_songs that contains the ID, title, and artist from the
DJs on Demand table for each “New Age” type code. In the subquery, use the alias “Song
Title” for the title column.

3. SELECT *
FROM view_d_songs.
What was returned?
4. REPLACE view_d_songs. Add type_code to the column list. Use aliases for all columns.

Tampilan Table:
5. Jason Tsang, the disk jockey for DJs on Demand, needs a list of the past events and those
planned for the coming months so he can make arrangements for each event’s equipment
setup. As the company manager, you do not want him to have access to the price that
clients paid for their events. Create a view for Jason to use that displays the name of the
event, the event date, and the theme description. Use aliases for each column name.

Tampilan Table:
6. It is company policy that only upper-level management be allowed access to individual
employee salaries. The department managers, however, need to know the minimum,
maximum, and average salaries, grouped by department. Use the Oracle database to
prepare a view that displays the needed information for department managers.

Tampilan Table:
Section 15.2

Use the DESCRIBE statement to verify that you have tables named copy_d_songs,
copy_d_events, copy_d_cds, and copy_d_clients in your schema. If you don't, write a query
to create a copy of each.

*copy_d_songs*

*copy_d_events*
*copy_d_cds*

*copy_d_clients*
1. Query the data dictionary USER_UPDATABLE_COLUMNS to make sure the columns in
the base tables will allow UPDATE, INSERT, or DELETE. Use a SELECT statement or
the Browse Data Dictionary feature in HTML DB. All table names in the data dictionary
are stored in uppercase.
*copy_d_songs*

*copy_d_events*
*copy_d_cds*

*copy_d_clients*
2. Use the CREATE or REPLACE option to create a view of all the columns in the
copy_d_songs table called view_copy_d_songs.
Tampilan Table:

3. Use view_copy_d_songs to INSERT the following data into the underlying copy_d_songs
table. Execute a SELECT * from copy_d_songs to verify your DML command. See the
graphic.
ID TITLE DURATION ARTIST TYPE_CODE
88 Mello Jello 2 The What 4
*Baris pada table menjadi bertambah*

4. Create a view based on the DJs on Demand COPY_D_CDS table. Name the view
read_copy_d_cds. Select all columns to be included in the view. Add a WHERE clause to
restrict the year to 2000. Add the WITH READ ONLY option.

Tampilan table:
5. Using the read_copy_d_cds view, execute a DELETE FROM read_copy_d_cds WHERE
cd_number = 90;

6. Use REPLACE to modify read_copy_d_cds. Replace the READ ONLY option with
WITH CHECK OPTION CONSTRAINT ck_read_copy_d_cds. Execute a SELECT *
statement to verify that the view exists.
Tampilan table:

7. Use the read_copy_d_cds view to delete any CD of year 2000 from the underlying
copy_d_cds.
Tampilan table:

8. Use the read_copy_d_cds view to delete cd_number 90 from the underlying copy_d_cds
table.
9. Use the read_copy_d_cds view to delete year 2001 records.

10. Execute a SELECT * statement for the base table copy_d_cds. What rows were
deleted?
11. What are the restrictions on modifying data through a view?
 Cannot remove a row if the view contains;
Group functions, a GROUP BY clause, The DISTINCT keyword, The pseudocolumn
ROWNUM Keyword.
 Cannot modify data through a view if the view contains:
Group functions, a GROUP BY clause, The DISTINCT keyword, The pseudocolumn
ROWNUM keyword, Columns defined by expressions.
 Cannot add data through a view if the view includes:
Group functions, a GROUP BY clause, the DISTINCT keyword, the pseudocolumn
ROWNUM keyword, columns defined by expressions, does not include NOT NULL
columns in the base tables.

12. What is Moore’s Law? Do you consider that it will continue to apply indefinitely? Support
your opinion with research from the internet.
Hukum Moore adalah salah satu hukum yang terkenal dalam industry
mikroprossesor yang menjelaskan tingkat pertumbuhan kecepatan mikroprosesor.
Perkembangan teknologi dewasa ini menjadikan Hukum Moore semakin
tidak Relevan untuk meramalkan kecepatan mikroprossesor. Hukum Moore, yang
menyatakan bahwa kompleksitas sebuah mikroprosesor akan meningkat dua kali lipat tiap
24 bulan sekali, sekarang semakin dekat ke arah jenuh. Secara tidak langsung, Hukum
Moore menjadi umpan balik (feedback) untuk mengendalikan laju peningkatan jumlah
transistor pada keping IC. 

13. What is the “singularity” in terms of computing?


Singularitas teknologi atau singularitas (Singularity), adalah suatu masa
ketika kecerdasan buatan berkembang jauh sehingga melampaui kecerdasan manusia dan
mengubah peradaban dan umat manusia. Karena kemampuan kecerdasan semacam itu
sulit untuk dipahami manusia, singularitas teknologi sering dipandang sebaagai peristiwa
(mirip singularitas gravitasi) yang setelahnya masa depan umat manusia tak dapat
diprediksi atau bahkan tak dapat diukur.

Section 15.3

1. Create a view from the copy_d_songs table called view_copy_d_songs that includes only
the title and artist. Execute a SELECT * statement to verify that the view exists.

Tampilan table:
2. Issue a DROP view_copy_d_songs. Execute a SELECT * statement to verify that the view
has been deleted.

3. Create a query that selects the last name and salary from the Oracle database. Rank the
salaries from highest to lowest for the top three employees.
4. Construct an inline view from the Oracle database that lists the last name, salary,
department ID, and maximum salary for each department. Hint: One query will need to
calculate maximum salary by department ID.

5. Create a query that will return the staff members of Global Fast Foods ranked by salary
from lowest to highest.
Extension Exercises

1. Create a new table called my_departments and add all columns and all rows to it using a
subquery from the Oracle departments table. Do a SELECT * from my_departments to
confirm that you have all the columns and rows.

Tampilan Table:
2. To view any constraints that may affect the my_departments table, DESCRIBE
my_departments to check if any constraints were carried over from the departments table.
If there are constraints on my_departments, use an ALTER TABLE command to
DISABLE all constraints on my_departments.

*mencari nama constraint untuk alter table*


3. Create a view called view_my_departments that includes: department_id and
department_name.

Tampilan Table:
4. Add the following data to the my_departments table using view_my_departments.
Department_id Department_name
105 Advertising
120 Custodial
130 Planning

*INSERT INTO untuk masing-masing baris*

Tampilan Tabel setelah dimasukkan data:


5. Create or enable the department_id column as the primary key.

6. Enter a new department named Human Resources into the my_departments table using
view_my_departments. Do not add a new department ID.

*SQL error, tidak dapat memasukkan (insert) NULL ataupun angka*


7. Add the Human Resources department, department ID 220, to my_departments using
view_my_departments.
8. Verify that the new additions to my_departments were added using
view_my_departments.
See chart below

9. Modify view_my_departments to include location ID. Do a SELECT * command to show


what columns are present and a DESCRIBE command to view the columns and associated
constraints.
10. Make location_id a NOT NULL column in the my_departments table.

*karena ketika di alter SQL tersebut error, maka dibuat terlebih dahulu location_id =
1800*
*kembali lagi ke ALTER TABLE, lalu DESCRIBE. Location_id berubah menjadi “NOT
NULL” seperti di bawah ini*
11. Using the Oracle database, create a complex view between locations and departments with
only the following columns: department_name, street_address, city, and state. Include
only U.S. cities. Verify that the view was created using a SELECT * statement.
See chart below

Tampilan table:

You might also like